[vtkusers] questions on vtk4.0 static libs and vtkPrintLeaksExit

c v covkmhk at yahoo.com
Sat Mar 16 23:03:55 EST 2002


 
I  built vtk4.0 static libs and linked it with the
SampleMFC.
When I exit the SampleMFC.exe, there pops up a dialog
with "SampleMFC has a error (Kernal32.dll) and will be
closed".
 
If I select Debug, I can see the VC's Call Stack :
"
KERNEL32! bff6bbd7()
vtkDebugLeaks::DestructClass(const char * 0x007a14b8
`string') line 302
vtkObject::UnRegister(vtkObject * 0x00000000) line 278
+ 31 bytes
vtkObject::Delete() line 154 + 15 bytes
vtkObjectFactory::UnRegisterAllFactories() line 447 +
18 bytes
vtkPrintLeaksAtExit::~vtkPrintLeaksAtExit() line 69
$E23() + 13 bytes
doexit(int 0, int 0, int 0) line 353
exit(int 0) line 279 + 13 bytes
WinMainCRTStartup() line 345
KERNEL32! bff7bced()
KERNEL32! bff7bb9f()
KERNEL32! bff7a558()
"
 
When I trace into, it shows it is the
vtkPrintLeaksAtExit::~vtkPrintLeaksAtExit()
caused this.
The related calls are as fellows:
 
  ~vtkPrintLeaksAtExit()
    {
 ===>     vtkObjectFactory::UnRegisterAllFactories();
      vtkOutputWindow::SetInstance(0);
      vtkDebugLeaks::PrintCurrentLeaks();
      vtkDebugLeaks::DeleteTable();
    } 
=======================================
 
void vtkObjectFactory::UnRegisterAllFactories()
{
  // do not do anything if this is null
  if( ! vtkObjectFactory::RegisteredFactories )
    {
    return;
    }
  int num =
vtkObjectFactory::RegisteredFactories->GetNumberOfItems();
  // collect up all the library handles so they can be
closed
  // AFTER the factory has been deleted.
  void** libs = new void*[num+1];
  vtkObjectFactory* factory = 0;
 
vtkObjectFactory::RegisteredFactories->InitTraversal();
  int index = 0;
  while((factory =
        
vtkObjectFactory::RegisteredFactories->GetNextItem()))
    {
    libs[index] = factory->LibraryHandle;
    }
  // delete the factory list and its factories
==========> 
vtkObjectFactory::RegisteredFactories->Delete();
  vtkObjectFactory::RegisteredFactories = 0;
  // now close the libraries
  for(int i = 0; i < num; i++)
    {
    void* lib = libs[i];
    if(lib)
      {
     
vtkDynamicLoader::CloseLibrary(reinterpret_cast<vtkLibHandle>(lib));
      }
    }
  delete [] libs;
}
 
               Here num=0;
======================================
void vtkObject::Delete() 
{
  this->UnRegister((vtkObject *)NULL);
}
======================================
void vtkObject::UnRegister(vtkObject* o)
{
  if (o)
    {
    vtkDebugMacro(<< "UnRegistered by "
      << o->GetClassName() << " (" << o << "),
ReferenceCount = "
      << (this->ReferenceCount-1));
    }
  else
    {
    vtkDebugMacro(<< "UnRegistered by NULL,
ReferenceCount = "
     << (this->ReferenceCount-1));
    }
 
  if (--this->ReferenceCount <= 0)
    {
#ifdef VTK_DEBUG_LEAKS
===========>   
vtkDebugLeaks::DestructClass(this->GetClassName());
#endif
    // invoke the delete method
    this->InvokeEvent(vtkCommand::DeleteEvent,NULL);
    delete this;
    }
}
 
                Here o = NULL
=====================================
void vtkDebugLeaks::DestructClass(const char* p)
{
  DebugLeaksCritSec.Lock();
  // Due to globals being deleted, this table may
already have
  // been deleted.
==========>  if(vtkDebugLeaks::MemoryTable &&
!vtkDebugLeaks::MemoryTable->DecrementCount(p))
    {
    DebugLeaksCritSec.Unlock();
    vtkGenericWarningMacro("Deleting unknown object: "
<< p);
    }
  else
    {
    DebugLeaksCritSec.Unlock();
    }
}
 
======================
 
Can you tell me why and how to fix it?
 
Thanks advance
 
Colin
 

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
http://sports.yahoo.com/



More information about the vtkusers mailing list