[vtkusers] Error when deleting a vtkImageData object !

David Doria daviddoria+vtk at gmail.com
Fri Jan 1 09:38:17 EST 2010


 Fri, Jan 1, 2010 at 9:03 AM, pof <jd379252 at gmail.com> wrote:
> Hi vtk'ers
>
> I'm having a problem when I'm deleting a vtkImageData object.
> I obtain the following error message (located in
> vtkImageAlgorithm::Execute()) :
> "Definition of Execute() method should be in subclass and you should really
> use the ExecuteData(vtkInformation *request,...) signature instead"
>
> Up to now, I've found no other workaround than NOT deleting the object,
> which I'm obviously not really happy with.
>
> Herebelow is a small sample code that reproduces the problem (I'm using
> vtk5.0.4 under MSVC++8).
>
> Any idea where my mistake comes from?
> JD.
>
>   // Define vtk objects
>   vtkBMPReader* m_ImageReader = vtkBMPReader::New();
>   vtkImageData* m_ImageData = vtkImageData::New();
>   vtkTexture* m_Texture = vtkTexture::New();
>
>   // Read bmp file
>   m_ImageReader->SetFileName("Image.bmp");
>   // Get data from image file
>   m_ImageData = m_ImageReader->GetOutput();
>   m_ImageData->Update();
>   // Assign data to texture
>   m_Texture->SetInput(m_ImageData);
>   m_Texture->Update();
>   // Other stuff
>   // ...
>   // ...
>   // Now do some cleaning
>   m_ImageReader->Delete();
>   m_ImageData->Delete(); //  Commenting this line  "solve" the error !
>   m_Texture->Delete();
>
> _______________________________________________
> 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
>

Try using smart pointers - no need to call delete:

#include <vtkSmartPointer.h>
  // Define vtk objects
  vtkSmartPointer<vtkBMPReader> m_ImageReader =
vtkSmartPointer<vtkBMPReader>::New();
  vtkSmartPointer<vtkImageData> m_ImageData =
vtkSmartPointer<vtkImageData>::New();
  vtkSmartPointer<vtkTexture> m_Texture = vtkSmartPointer<vtkTexture>::New();

  // Read bmp file
  m_ImageReader->SetFileName("Image.bmp");

// you need to call Update() to actually read the file
m_ImageReader->Update();

  // Get data from image file
  m_ImageData = m_ImageReader->GetOutput();

  m_ImageData->Update(); // I don't know if update here is necessary?

  // Assign data to texture
  m_Texture->SetInput(m_ImageData);
  m_Texture->Update();


Give that a try and let us know if it fixes the problem. There is a
smart pointer tutorial here;
http://www.cmake.org/Wiki/VTK/Examples/SmartPointers

Thanks,

David



More information about the vtkusers mailing list