[vtkusers] segmentation fault with vtkImageData and vtkMetaImageReader

Laurent Mundeleer laurent.mundeleer at uclouvain.be
Tue Jun 7 07:20:48 EDT 2011


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





More information about the vtkusers mailing list