[vtkusers] Delete on vtkPolyDataReader

Francis Bouchet francis.bouchet at areall.com
Tue Nov 14 12:27:15 EST 2000


Hello,

I'm working with vtk 3.1 on NT4.0 SP4 / Visual C++ 6.0.
I have problems with memory deallocations.

For instance, in the following example, I use a vtkPolyDataReader, and I
want to use the resulting vtkPolyData.
I first get the output of the reader in a temporary vtkPolyData variable,
and then I want to deallocate the reader, but if I do so, my temporary
variable points a wrong memory place :

----------------------------------------------------------------------------
--------------------

vtkPolyDataReader *PolyDataReader = vtkPolyDataReader::New();
vtkPolyData *PolyData;

PolyDataReader->SetFileName(FileName);
PolyData =  PolyDataReader->GetOutput();
PolyData->Update();
PolyDataReader->Delete();
printf("pts read : %d\n", PolyData->GetNumberOfPoints() );


----------------------------------------------------------------------------
--------------------

In order to avoid this problem, I can choose not to deallocate the reader,
but in this case my program doesn't end properly.
(This code lines are actually in a loop, and this function is supposed to be
executed many times, and after a lot of iterations the program crashes on a
New() or a Delete() statements.

Can somebody explain me the correct way to use New() and Delete() statements
in this case?
When I delete the reader, how can I still keep the generated PolyData?
This question concerns also vtkPolyData when it is constructed through a
SetPoints() :
Shall I delete the vtkPoints AND the PolyData, or only the PolyData (since
it includes the vtkPoints) ?

Could somebody help me please ?

Thank you,

Francis.





More information about the vtkusers mailing list