[Insight-users] BCB5 and itk - please help

Luis Ibanez luis.ibanez@kitware.com
Tue, 18 Feb 2003 12:37:27 -0500


Hi Dean,

The implementation of your TForm class looks good.

Is the application running Ok ?

It looks like the only problem is the destruction
of objects on exit... is that right ?

Does the output of the filter looks satifactory ?

------

Here are some suspects that come to mind:

1) You are not definining a copy constructor for
    your TForm class. Is there any chance that
    the form is being passed by copy at some point ?

    This will result in an invalid copy of the
    smart pointer to the filter.


2) Are you multithreading the GUI ?

    If you are creating the form in on thread and
    attempting to destroy it in another thread
    this may lead to inconsitent values in the
    reference counting mechanism.


3) Are you building a DLL for your application ?


4) Does the base class TForm have any virtual
    methods ?

    The destructor of your derived class TForm1
    is not being declared virtual. If TForm
    happens to be an abstract class, this may
    lead to calling incorrect destructors when
    it comes the time of removing the form.

    (Although, from your callstack it looks like
     the right destructor ~TForm1 is being invoked)

5) Are you passing the Output of the filter to
    some other component in your application ?

    If so, Are you doing this using a SmartPointer
    or a raw pointer ?

    It may be that the destruction problem we are
    facing is not due to the actual filter object
    but rather the destruction of its input image
    or its output image.

    From your callstack, it seems that the crash
    actually happens in a call to itk::DataObject
    Initialize() method, from the destructor of the
    ProcessObject. It may be that the list of outputs
    or inputs of the filters has been corrupted.

    E.g. Are you using by any chance something like
    SetOutput() in the filter ? or GraftOutput() ?

6) Could this happen after an exception has been
    thown and catched in your app. It may be that
    the application is trying to run code that has
    been left in an unconsistent state after an
    exception has been thrown.

7) Do you have access to the source code of the "CreateForm()"
    function invoked in your main()  ?

    It looks like factory that is using RTTI information
    in order to determine which type of object to create.

    I wonder is a wrong type of object is being created
    and returned.



Please let us know if any of these suspects could
lead to other hints.

Thanks


   Luis


---------------------------------
dean.inglis@on.aibn.com wrote:
> 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;
> }
> //---------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
> 
>