[vtkusers] initialization missing in vtkImageCanvasSource2D constructor

xabi riobe xabivtk at gmail.com
Wed Dec 6 08:23:58 EST 2006


Hello,

I noticed that the attribute
   int WholeExtent[6];
of the class vtkImageCanvasSource2D is not initialized, and that makes
an application crash in some specific cases.

For exemple, entering twice in a method containing the following piece
of code generates the following error the second time:

ERROR: In \VTKRelease\src\Filtering\vtkImageData.cxx, line 1450
vtkImageData (0C5CB9F0): GetScalarPointer: Pixel (-1, -1, 0) not in memory.
 Current extent= (0, -1, 0, -1, 0, -1)


code:

ScreenShot()
{
...
   vtkWindowToImageFilter *w2i = vtkWindowToImageFilter::New();
   vtkImageCanvasSource2D *img = vtkImageCanvasSource2D::New();
...
   img->SetScalarTypeToUnsignedChar();
   img->SetNumberOfScalarComponents(3);
   img->SetExtent(0,nWidth-1,0,nHeight-1,0,0);
   img->DrawImage(nX,nY,w2i->GetOutput());     // error occurred here
...
   img->Delete();
   w2i->Delete();
}


if the line
   img->SetExtent(0,0,0,0,0,0);
is inserted before the previous SetExtent, then everything works good.

that's because in SetExtent, the parameters are compared with
this->WholeExtent[]
and if at the second ScreenShot() call the "img" pointer has the same
adress as the previous one after the New(), this->WholeExtent[] will
point to the same memory adress and the previous values.

This could be avoided with the initialization in the constructor:
for(int i=0; i<6; ++i)
  this->WholeExtent[i] = 0;



More information about the vtkusers mailing list