[Insight-users] BCB5 and itk - please help - solved!

Dean Inglis dean.inglis@on.aibn.com
Wed, 19 Feb 2003 10:10:49 -0500


Hi Bill,

thanks for the pointer info.  What I have done is
created an Close event for the Form which
appears to work (I'm keeping my fingers crossed):

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
  itkImporter = 0;
  filter = 0;
  itkExporter = 0;
}

I tried with just the filter and then added in the itkImporter and
itkExporter
from Auxiliary/vtk/itkVTKtoITKtoVTK.cxx.  So now the app works in debug and
release mode when running from the IDE and from a windows command prompt!

Oddly though, I had tried this before and was getting access violations
so perhaps one or more temporary files in the IDE's build process
were not completely up to date ???

Anyway, thankyou Bill and everyone else for your patience and help.

Dean


>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