[vtkusers] Error when deleting a vtkImageData object !
pof
jd379252 at gmail.com
Fri Jan 1 12:49:26 EST 2010
Mike,
my mistake, obviously!! I just couldn't see it (it might not be a good
idea after all to debug code with only few hours of sleep).
Thanks a lot for your perspicacity, and all the best for 2010.
JD
Michael Jackson a écrit :
> // Define vtk objects
> vtkBMPReader* m_ImageReader = vtkBMPReader::New();
>
> // Below you are create a pointer to a newly created vtkImageData object
> vtkImageData* m_ImageData = vtkImageData::New();
> // You should really have something like:
> vtkImageData* m_ImageData = NULL;
>
> vtkTexture* m_Texture = vtkTexture::New();
>
> // Read bmp file
> m_ImageReader->SetFileName("Image.bmp");
> // Get data from image file
> //Now you are are assigning the vtkImageData Object from the BMPReader
> to your
> // m_ImageData Pointer, which leaves the first pointer you created
> dangling
> // which is a MEMORY LEAK.
> m_ImageData = m_ImageReader->GetOutput();
> // If you really want to keep a reference to the output of the
> m_ImageReader around
> // then you need to increase it's reference count by "Registering" it
> m_ImageData->Register(NULL);
>
> m_ImageData->Update();
> // Assign data to texture
> m_Texture->SetInput(m_ImageData);
> m_Texture->Update();
> // Other stuff
> // ...
> // ...
> // Now do some cleaning
> // When you call "Delete" on the m_ImageReader, it will also "Delete" the
> // m_ImageData because the reference count would drop to Zero. If you
> had actually
> // "Registered" it (as above), then YOU need to also "UnRegister" it
> by calling
> // Delete() on the m_ImageData object.
> m_ImageReader->Delete();
> m_ImageData->Delete(); // Commenting this line "solve" the error !
> m_Texture->Delete();
>
> If you don't really need the m_ImageData object for anything else, you
> should be able to
> directly hook up the vtkBMPReader to the vtkTexture and then just call
> "Update" on the vtkTexture object.
>
> HTH
> Mike Jackson
>
>
> On Jan 1, 2010, at 9:03 AM, pof 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();
>>
>> _______________________________________________
>
>
More information about the vtkusers
mailing list