[vtkusers] VTK python wrapping issue -- collections

tom fogal tfogal at apollo.sr.unh.edu
Thu May 19 12:51:16 EDT 2005


Hi all, I think I might have found a bug in the way
Actor(all?)Collections are passed between C++ and Python. I was hoping
someone had an idea for a workaround. Basically ActorCollections are
losing their Actors when being passed from Python -> C++.

Basically my setup is that: python is given a vtkDataSet. The script
then does whatever it wants, then eventually passes back a
vtkActorCollection with 1 or more actors in it.

This breaks down when python returns though. I suspect I am running
into a python-destruction (for lack of a better term) problem. The
ActorCollection is populated by Actors that are instantiated from
python. When PyObject_CallFunction(...) returns though, the Actors are
tagged (rightly, I suppose) as pure-python objects, and thus of course
to prevent memory leaks their memory must be reclaimed. However the
vtkActorCollection that I am getting back still references them.

It seems as if python also uses reference counting for memory
management. My guess is that even though vtkActorCollection has a
(python) reference count of 1 (since it must be returned to C++),
python has no way of knowing that Actors created in the python script
are referenced by the vtkActorCollection object; that is, the python
reference count of the actors becomes 0 while the vtk reference count
is still 1 (from the ActorCollection).

Could anybody confirm this? Even better, could somebody suggest a fix
or workaround?

-tom

BTW, I've noticed documentation on this subject is not so great. I
would be willing to (more) verbosely comment my current working source
and share it to contribute to the existing dearth, although I'm not
sure where to send it off to...



More information about the vtkusers mailing list