[Insight-users] BCB5 and itk - please help

Bill Hoffman bill.hoffman@kitware.com
Wed, 19 Feb 2003 09:22:08 -0500


>you cannot do this:
>
>filter = FilterType::New();
>filter->UnRegister();

You can not do this with any itk code, Borland or not.
If you want to get around the smart pointers you could do this:
class SomeClass
{
FilterType* ptr;  // declare a real pointer to the filter
...
};


SomeClass::SomeClass()
{
FilterType::Pointer p = FilterType::New();  // create the smart pointer
FilterType* ptr = p.GetPointer();  // get the real pointer from the smart pointer
this->ptr->Register();  // Register the object so that the smart pointer will not delete the objct
...
}

SomeClass::~SomeClass()
{
this->ptr->UnRegister();  // unregister the real pointer
}

The smart pointers destructor is a simple call to UnRegister.

However, I do not think the above will fix you problem.
I think the problem is that the destruction of the form happens
in _exit.   

This call stack is telling:

0041DA89 itk::TimeStamp::Modified
.....
0047476C _exit
00475680 __startup

It means that it is crashing in the destructor of the object when it
calls Modified.    This touches a global variable, and my guess is that
variable has already been destroyed.   

Is there some Close Event or other some other place in the Form that gets
called when the application quits that you can set the smart pointer to 0?
I don't really know how the borland framework works, but MFC has various Close,
or Quit events that you can put code in.   If there is something like that,
you should just set the smart pointer to 0 at that point.   I think that
the Forms destructor is called too late.


-Bill