[Insight-users] SmartPointer problem

Bill Hoffman bill . hoffman at kitware . com
Thu, 26 Jun 2003 09:27:07 -0400


The problem is what I thought it was.   Your function returns
a smart pointer via a regular pointer.   GetOutput returns a smartpointer,
so the GetOutput call deletes the ImageType before exiting the function
itkWrapFilter and you get a crash.    You have to return 
ImgetType::Pointer to make it work.


ImageType* itkWrapFilter(ImageType* inputimage)
{
....
return filtern->GetOutput();  // this creates a temporary smart pointer 
// that is deleted by the end of this line of code, but before the 
// return statement, so the function returns a deleted pointer.
}  



At 05:04 PM 6/25/2003, Shunming Fang wrote:
>Hello, Bill,
>My function look like:
>ImageType* itkWrapFilter(ImageType* inputimage)
>{
>    declare filter1,.. filtern
>    filter1->SetInput(inputImage);
>    filter2->SetInput(filter1->GetOutput());
>     :
>     :
>    filtern->SetInput(filtern-1->GetOutput());
>    return filtern->GetOutput();  

>}
>
>Do you think anything missing? or I need call
>filtern->Update() inside function, then the data will
>getout?
>Thanks 
>
>--- Bill Hoffman <bill . hoffman at kitware . com> wrote:
>> 
>> What does the itkWrapFilters function look like?
>> My guess is that it returns a smartpointer as a real
>> pointer, and when the smartpointer goes out of
>> scope, the
>> pointer is deleted before it even gets to the
>> operator =.
>> 
>> -Bill
>> 
>> 
>> At 04:11 PM 6/25/2003, Shunming Fang wrote:
>> >Hello, ITK_Users:
>> >I declare a ImageType smartpoint like:
>> >TmageType::pointer image;
>> >image = itkWrapFilters(InputImage), there, I found
>> >when 
>> >smartpointer try to copy assigment, there happened
>> of
>> >Segmentation fault, anything wrong?
>> >Fang
>> >
>> >__________________________________
>> >Do you Yahoo!?
>> >SBC Yahoo! DSL - Now only $29.95 per month!
>> >http://sbc . yahoo . com
>> >_______________________________________________
>> >Insight-users mailing list
>> >Insight-users at itk . org
>> >http://www . itk . org/mailman/listinfo/insight-users 
>> 
>> 
>> 
>> _______________________________________________
>> Insight-users mailing list
>> Insight-users at itk . org
>> http://www . itk . org/mailman/listinfo/insight-users
>
>
>
>__________________________________
>Do you Yahoo!?
>SBC Yahoo! DSL - Now only $29.95 per month!
>http://sbc . yahoo . com