ODE Crash when trying to destroy object in onContact()

When I try to destory the object in question in the onContact method I get the following error

# An unexpected error has been detected by HotSpot Virtual Machine:
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x065c3863, pid=3880, tid=3080
# Java VM: Java HotSpot(TM) Client VM (1.5.0_01-b08 mixed mode, sharing)
# Problematic frame:
# C  [odejava.dll+0x23863]
# An error report file with more information is saved as hs_err_pid3880.log
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
[error occurred during error reporting, step 120, id 0xc0000005]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J  org.odejava.ode.OdeJNI.dWorldQuickStep(JF)V
J  com.jmex.physics.PhysicsWorld.update(F)V
J  com.meka.system.GameSystem.update(F)V
J  com.meka.app.Game.update(F)V
J  com.jme.app.FixedLogicrateGame.start()V
v  ~OSRAdapter
j  com.meka.app.Game.main([Ljava/lang/String;)V+14
v  ~StubRoutines::call_stub

basically, I have a ton of bullets flying around. Each bullet has an onContact method that destroys the PhysicsObject and Geometry for that bullet upon collision with a ship node.. I can imagine how this might be a problem if you destroy the physicsObject in the onContact call since on return ODE probably assumes the object still exists?

Is this a known problem and what's a good work around?

I'm thinking have the ship physics object check to see if a bullet collided with it so the shipObject destorys the bullets rather than the bullets trying to destroy themselves.


I tried moving the bullet destruction to the ship's onContact method but it I will get the crash. This is gonna be annoying. It only happens once in a while.

Right, ok, we never actually anticipated the contactAction method to be (ab)used in this way ;), i.e. containing logic mixed with physics.

What I can suggest to you is tho is to create a Singelton manager whereby on things you want to delete, you register with this manager. and only AFTER the update physics call, do you start deleting things. This is because the contact stuff are actually being called during an update and that just confuses ode when your trying to remove things during update.

Anyway, if you pool everything that has been collided and need removing in an arraylist or something and then just loop through it and call the removeObject on the physicsSystem, that should work.

Btw, I have thought of a solution to stop people (ab)using contactAction this way. Should be in CVS soonish (depending on how well my plans turn out!)


Okay … thanks DP. Never meant to abuse it haha.

hehe, its just that me and per never anticipated people putting in game logic in there thats all. Infact, i actually think its a good idea, it just needs to be handled different thats all.

The fix should be in CVS soon.


Ok, the PhysicsCollisionResult stuff has been commited to CVS. Please see SimpleTest on how to use it.