[Insight-users] BCB5 and itk - please help

dean.inglis@on.aibn.com dean.inglis@on.aibn.com
Tue, 18 Feb 2003 10:08:21 -0500


Ok, last ditch appeal for help.  Here is the call stack for
simple Borland C++ Builder GUI app that instantiates an itk
object (BinomialBlurImageFilter) in the form's constructor.
On exiting the app, it appears that the itk object proceeds
through its destruction sequence, but after the form that
owns it is destroyed, thereby resulting in memory access
violation:


77F85C41 ntdll.dll
77F85BD1 ntdll.dll
004279FD itk::TimeStamp::Modified
004215A9 itk::Object::Modified
0041CF8D itk::DataObject::Initialize
00425097 itk::ProcessObject::~ProcessObject
004055E7 itk::ImageSource<itk::Image<float, 2> >::~ImageSource<itk::Image<float, 2> >(this=:01044E54)
00408E33 itk::ImageToImageFilter<itk::Image<float, 2>, itk::Image<float, 2> >::~ImageToImageFilter<itk::Image<float, 2>, itk::Image<float, 2> >(this=:01044E54)
004054CB itk::BinomialBlurImageFilter<itk::Image<float, 2>, itk::Image<float, 2> >::~BinomialBlurImageFilter<itk::Image<float, 2>, itk::Image<float, 2> >(this=:01044E54)
0041F4AE itk::LightObject::UnRegister
00421B85 itk::Object::UnRegister
004036D5 itk::SmartPointer<itk::BinomialBlurImageFilter<itk::Image<float, 2>, itk::Image<float, 2> > >::UnRegister(this=:01042FC0)
00403644 itk::SmartPointer<itk::BinomialBlurImageFilter<itk::Image<float, 2>, itk::Image<float, 2> > >::~SmartPointer<itk::BinomialBlurImageFilter<itk::Image<float, 2>, itk::Image<float, 2> > >(this=:01042FC0)
0040386E TForm1::~TForm1(this=:01042CEC)
0045BD31 Classes::TComponent::DestroyComponents
0047EB3B __init_exit_proc
0047EB8A __cleanup
0047DE4C _exit
0047ED60 __startup

Here is what happens if the filter is initialized with ->DebugOn() :

77F85C41 ntdll.dll
77F85BD1 ntdll.dll
004279F5 itk::TimeStamp::Modified
004215A1 itk::Object::Modified
00421FA5 itk::Object::Object
004243BE itk::OutputWindow::OutputWindow
00424882 itk::Win32OutputWindow::New
00424778 itk::OutputWindow::GetInstance
004245A0 itk::OutputWindowDisplayDebugText
00421A28 itk::Object::UnRegister
004036CD itk::SmartPointer<itk::BinomialBlurImageFilter<itk::Image<float, 2>, itk::Image<float, 2> > >::UnRegister(this=:01042FC0)
0040363C itk::SmartPointer<itk::BinomialBlurImageFilter<itk::Image<float, 2>, itk::Image<float, 2> > >::~SmartPointer<itk::BinomialBlurImageFilter<itk::Image<float, 2>, itk::Image<float, 2> > >(this=:01042FC0)
00403866 TForm1::~TForm1(this=:01042CEC)
0045BD29 Classes::TComponent::DestroyComponents
0047EB33 __init_exit_proc
0047EB82 __cleanup
0047DE44 _exit
0047ED58 __startup


I have enclosed the relevant files for anyone who would like to 
verify this behaviour. ITK is build with CMake 1.6.4, MinSizeRel,
Borland compiler on Win 2k, single Pentium 4 processor.  I have
also posted to the Borland newsgroups but without much success.
Any help would be great,


Dean


Here is the form's class definition (itkObjectTest.h):

//---------------------------------------------------------------------------

#ifndef itkObjectTestH
#define itkObjectTestH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>

#include "itkImage.h"
#include "itkBinomialBlurImageFilter.h"

//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
        TLabel *Label1;
private:	// User declarations
public:		// User declarations
        __fastcall TForm1(TComponent* Owner);
        __fastcall ~TForm1();

    typedef itk::Image<float, 2> ImageType;
    typedef itk::BinomialBlurImageFilter< ImageType, ImageType >  FilterType;
    FilterType::Pointer filter;

};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


Here is the implementation (itkObjectTest.cpp):

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "itkObjectTest.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
  filter = FilterType::New();
}
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
  return;
}


Here is the form's GUI element description (itkObjectTest.dfm):

object Form1: TForm1
  Left = 197
  Top = 304
  Width = 279
  Height = 181
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 80
    Top = 48
    Width = 100
    Height = 32
    Caption = 'ITK Test'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -27
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    ParentFont = False
  end
end



Here is the application implementation (itkObjTestPrj.cpp):

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
USERES("itkObjTestPrj.res");
USEFORM("itkObjectTest.cpp", Form1);
USELIB("..\..\Backup\VXLNumerics.lib");
USELIB("..\..\Backup\ITKBasicFilters.lib");
USELIB("..\..\Backup\ITKCommon.lib");
USELIB("..\..\Backup\ITKAlgorithms.lib");
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
        try
        {
                 Application->Initialize();
                 Application->CreateForm(__classid(TForm1), &Form1);
                 Application->Run();
        }
        catch (Exception &exception)
        {
                 Application->ShowException(&exception);
        }
        return 0;
}
//---------------------------------------------------------------------------