[vtkusers] segmentation fault with vtkImageData and vtkMetaImageReader

Jérôme jerome.velut at gmail.com
Wed Jun 8 10:42:56 EDT 2011


Hi,

You should use cast->SetInputConnection( reader->GetOutputPort( ) ); instead
of the old fashion SetInput.
IMHO, the problem is that your smart pointer, for some reasons (reference
count becomes null), decided to deallocate the reader, and thus the
underlying output.

HTH,
Jerome

2011/6/7 Laurent Mundeleer <laurent.mundeleer at uclouvain.be>

> Hi everyone,
> I have a strange problem in reading a MetaImage.
> I have a segmentation fault when I access the vtkImageData, but if I use a
> direct pointer instead of a smartPointer on the vtkImageReader it's ok (but
> I have a memory leak).
>
> What am I doing wrong ?
> Here are some code extracts of what is working :
>
> // in reader method :
> ...
> vtkImageData *imageData = 0;
> ...
>
> vtkMetaImageReader* reader = vtkMetaImageReader::New();
> //add to replace : vtkSmartPointer<vtkMetaImageReader> reader =
> vtkSmartPointer<vtkMetaImageReader>::New();
> // and have no delete at the end of the reading
> ..
> reader->Update();
> ...
> imageData = reader->GetOutput();
>
> // no delete on the reader
>
> /------------------------------------------
>
> // in renderer method :
>    vtkSmartPointer<vtkImageCast> castSource
> =vtkSmartPointer<vtkImageCast>::New();
>    castSource->SetOutputScalarTypeToUnsignedChar();
>    castSource->SetInput(imageData); // seg fault
>    castSource->Update();
>
> /---------------------------------------------
> // or in unit test :
> vtkImageData*volume = readingMethod();
> ...
> double *origin = volume->GetOrigin(); // seg fault
>
>
> Thank you for any help,
> Best Regards,
>
> ++
> Laurent
>
>
> _______________________________________________
> 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/20110608/15ce7827/attachment.htm>


More information about the vtkusers mailing list