With reference to the pyode thread here
and the problem outlined by Matthias Baas in the 5th email.
There are multiple destructors (for each object plus
dWorldDestroy, joint group destructors) within ode.
Some objects hold pointers to others that are used at
destructor time (eg. the Geom destructor tries to
unlink itself from its associated body, without
checking that the pointer is still valid).
This results in the situation where it isn't clear
which objects are still valid, and which have already
been free'd, so calling various destructors results in
memory problems which can cause segfaults (also visible
This is particularly a problem where the destructor
order is non-deterministic, as in pythons garbage
collection, as there is no way from within a pyode
program to force deallocation of specific ode objects.
At the moment I hack around this by explicitly
destroying pointers between ode objects on simulation
close by deattaching all joints and geoms from bodies, ie:
for j in self.joints:
for g in self.space:
I assume that this is also a problem with non-python
wrappers as well. Ode needs fixing so that the
ownership of objects for destruction is clear, and that
destructors don't reference pointers to other attached
objects that may already have been deallocated.