initialization missing in vtkImageCanvasSource2D constructor
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
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,300,0,300,0,0); img->DrawImage(nX,nY,w2i->GetOutput());//error occurred here ... img->Delete(); w2i->Delete(); }
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. something like this: for(int i=0; i<6; ++i) this->WholeExtent[i] = 0;