My application have to load different scenes repeatedly (synoptic views for SCADA application).
I need to clean-up properly the renderer between to scenes to avoid increasing memory usage.
I use a loop to clean-up like this:
vtkActorCollection* actors = vtkActorCollection::New();
actors = renderer->GetActors();
actors->InitTraversal();
vtkActor nextActor = actors->GetNextActor();
while (nextActor != NULL)
{
renderer->RemoveActor(nextActor);
nextActor->Delete(); // this line with access viloation
nextActor = actors->GetNextActor();
}
it works fine with simple objetcs (cubes…) or OBJ imported files but raise an “access violation” on the delete line if objects are loaded with GLTF importer.
is it a bug or there is another way to clean-up the scene ?
I use the 8.9.0 version of the VTK library.
You should not delete the actor, removing it is enough. You can also compile VTK with VTK_DEBUG_LEAKS CMake option to help you with the management of VTK resources.
It also looks like you will have a leak here on the vtkActorCollection object.
Try this: