Panda crashing when removing ODE object

Hello,

I’m making a FPS with Panda3D and ODE. When a bullet hits a cube, I try to destroy the cube. However, after I do that, Python crashes – not 100% of the time, but most of it – with the following error:

Assertion failed: (_flags & F_lock_count) != 0 at line 68 of c:\panda3d-1.7.0\built\include\mutexSimpleImpl.I

I can post more of my code later if necessary, but for now, I would like to know if I am performing the right steps to remove an object…

Considering obj is an object of a Box custom class of mine, which has node (a NodePath), geom (an OdeGeom) and body (an OdeBody) as attributes, I call these methods when I destroy a cube:

obj.node.detachNode()
obj.geom.destroy()
obj.body.destroy()

Am I missing anything (removing the body from the world, for example)? Am I doing something that I shouldn’t be doing, or out of the right order?

This code used to be called on the collision handler, but I thought that destroying an object in the middle of the physics step could be the cause of the crash, so I instead added it to a list and now I destroy, after the end of the physics step, all objects which are in the list. But I still get the same error.

Can anyone help me?

Thanks in advance,
JP

Hi Joao,

i experience the same error, didnt find a solution yet.

greetz
blaz

I solved my problem partially by changing the .destroy() calls to .disable(). But it doesn’t look like the best solution.

Same problem here. Maybe someone used to the ode-binding source may enlight us?

I’ve been working with ODE but so far I don’t destroy any objects. Tonight I will try adding that feature to my sandbox and see what happens. I will throw out a guess: what happens to obj (the Box instance) after that? Maybe an internal reference is keeping it alive. Make sure you remove it from any lists and remove any tasks or event handlers that might reference it. Maybe try settings those attributes to None and see if it still crashes or crashes with a different message.

obj.node.detachNode()
obj.geom.destroy()
obj.body.destroy()
obj.node = None
obj.geom = None
obj.body = None

I’m back. I added destroying bodies/geoms to my ODE sandbox and didn’t have any problems! I can only come up with two possibilities:

  1. You have a dangling reference, as I surmised.

  2. Geoms must be destroyed using the reference returned from OdeSpace.getGeom(index), because that’s how I did it. (I had to do it that way because I don’t hold onto a reference to the geoms anywhere.)

If #2 is the case, here is the relevant section of my code:

        geoms_to_destroy = []
        for geom_idx in range(space.getNumGeoms()):
            geom = space.getGeom(geom_idx)
            if geom.hasBody() and geom.getBody() == body_to_destroy:
                geoms_to_destroy.append(geom)
        print "Destroying", len(geoms_to_destroy), "geom(s)..."
        for geom in geoms_to_destroy:
            geom.destroy()

Other possibility: We use OdeTriMeshGeom.
My testcase: codepad.org/IQthQ8ru
With MyApp(False) only OdeBoxGeom will be used and everything is fine. But if one call it with True OdeTriMeshGeom will be used and things are getting nasty. If you comment the obj.update in you get an assertion from ode directly after some time.

I get an ODE-related crash when shutting down my Panda apps if they use a TriMesh.
It was fine when I used the standalone pyODE but I switched to the built-in ODE when Panda started using Python 2.6.
I’ve just been ignoring it for now but will need to resolve it eventually.

Ouch, you guys are right. I had only one OdeTriMesh, my terrain, which is of course static. Everything else I spawned has been the other simple shapes. So I just added spawning dynamic trimesh colliders and - [color=red]KABOOM - crashes everywhere. I got that odemath.h error a lot, seemed to be from intersecting trimeshes but was pretty random. However the mutexSimpleImpl error only happened upon application exit if there were more than 3 trimeshes in the world. It didn’t happen when there were less than 3, and it didn’t happen when I destroyed them all myself. Weird.

So what now? Does anybody know the one who has added ode to panda or someone who is supporting this part?

Hi all,

Hopefully I am talking about the same problem here.

I consistently get a windows crash report when I close panda with more than 2 or 3 ODE trimesh objects.

I spent some time working on this problem when I discovered every time I exited my game the PC was silently sending an error report to Microsoft or annoying the user with a “send report to Microsoft” dialog.

So I went into the panda source code to find the problem.

I found the code that causes my crash but not the original source of the problem.

I think the code producing the error can be found in the make panda source at panda\src\ode\odeTriMeshData.cxx around line 58 with a function void OdeTriMeshData::remove_data(OdeTriMeshData *data)

I think this function is called for some invalid objects. (Perhaps already destroyed)

My (poor) work around is to comment out the contents of this function and recompile panda. This solved the crash on exit. This is clearly not a good fix. If someone who is comfortable working on the panda source wanted to look at the problem hopefully this will be a pointer in the right direction.

Does this help anyone?