[vtkusers] Segmentation fault when Delete() is called on an output from a filter

Utkarsh Ayachit utkarsh.ayachit at kitware.com
Wed Jun 24 07:27:55 EDT 2009


As a general rule, you should not call delete on something that you didn't
create yourself. Hence you should not be calling Delete()on output of any
filter explicitly. The output dataset will be cleaned up automatically when
it's no longer referenced.
Utkarsh

On Wed, Jun 24, 2009 at 5:35 AM, Anthony <slam_ono at yahoo.com> wrote:

> Hi all,
>
> In this part of code I tried to create a new vtkImageData , pass it
> through vtkImageFlip , get the output and then tried to free the memory.
> Don't know why I get Segmentation fault , what could I be missing here?
> really appreciate any suggestion .
>
> vtkImageData *id =vtkImageData::New();
>         id->SetDimensions(10,25,100);
>         id->SetScalarTypeToUnsignedShort();
>         id->SetNumberOfScalarComponents(1);
>         id->AllocateScalars();
>
>     unsigned short *ptr= (unsigned short *) id->GetScalarPointer();
>     for(int i=0; i<10*25*100;i++)
>     {
>         *ptr++=i;
>     }
>
>     vtkImageFlip *flipX=vtkImageFlip::New();
>         flipX->SetInput(id);
>         flipX->SetFilteredAxis(0);
>         flipX->Update();
>
>     vtkImageData *id2=vtkImageData::SafeDownCast(flipX->GetOutput());
>
>     id->Delete();
>     flipX->Delete();
>     id2->Delete(); //probably because of this?
>
> Cheers,
>
> Anthony
>
> ------------------------------
>  New Email addresses available on Yahoo!
> <http://sg.rd.yahoo.com/aa/mail/domainchoice/mail/signature/*http://mail.promotions.yahoo.com/newdomains/aa/>
> Get the Email name you've always wanted on the new @ymail and @rocketmail.
> Hurry before someone else does!
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090624/f91e52ee/attachment.htm>


More information about the vtkusers mailing list