JV-ODE: Bug in dSpaceDestroy()

Blitz3D Forums/Blitz3D Userlibs/JV-ODE: Bug in dSpaceDestroy()

Danny(Posted 2006) [#1]
JV-ODE: Bug in dSpaceDestroy()

Before I load a new level (or game) I have to purge all the existing level data; include all bodies, joints and geometry I created for ODE. In stead of doing everything manually (and having a natural lazyness to prevent doing things not necesary) I use these three function to destroy whatever game data is used by ODE:
   dJointGroupDestroy(contactGroup)
   dSpaceDestroy(Space)
   dWorldDestroy(World)
According to the manual I think I should be safe. Especially with dSpaceDestroy which according to the docs is supposed to "When a space is destroyed, if it's cleanup mode is 1 (the default) then ALL THE GEOMS IN THAT SPACE ARE AUTOMATICALLY DESTROYED AS WELL".

I think not! My experience is that if I don't manually destroy each piece of geometry I created before, I get a guaranteed MAV the next time my game goes into the main loop and hits the ODE update routine:
   dSpaceCollide(space,world,contactGroup)    ; THIS WILL GENERATE A MEMORY ACCESS VIOLATION!
   dWorldQuickStep(world, 0.05)
   dJointGroupEmpty(contactGroup)
I've included an example here where I succesfully re-start ODE 3 times (manually purging geometry) but the 4th time will give a MAV because I didn't manually purge the geometry the 3rd time, and 'relied' on dSpaceDestroy() to do that for me...

Anyone had this problem?! Am I missing something?!



Cheers,
Danny.


VIP3R(Posted 2006) [#2]
Hmm, it's not a bug in that sense as ODE is actually correctly deleting the geoms when you destroy the space. However, it does highlight a problem that's been overlooked.

The problem arises because in JV-ODE, the geoms each have their own contact information attached (used to retrieve the detailed collision data). When you use the dGeomDestroy() function, this data is cleaned up and destroyed also.

But, when using the dSpaceDestroy() function, although ODE correctly destroys all geom instances, it doesn't cleanup and destroy the data that was attached to the old geoms (it isn't aware of the data internally). When you re-init the space and create new geoms, the old geom data still exists, so when you try to process the contacts using dSpaceCollide() it throws a MAV.

For the time being you will need to delete all geoms manually with dGeomDestroy() to correctly destroy the geom data and prevent the MAVs.

I agree this definitely needs looking at, I'll see if I can add the geom data cleanup code to the dSpaceDestroy() process. All should work as expected then.

Thanks for the detailed bug report Danny, I'll look into this right away ;)


Danny(Posted 2006) [#3]
Super reply vip3r, thanks for that!

Yes it would be good if you or one of the ode guys can incorporate cleaning that extra data with dSpaceDestroy()..

Cheers,
Danny


VIP3R(Posted 2006) [#4]
Ok, the dSpaceDestroy() issue is now fixed and will be included in the next JV-ODE update V1.12.

:)


Mustang(Posted 2006) [#5]
Whoo-ah - bugs sure have a hard time trying to stay alive in JV-ODE! :)


Damien Sturdy(Posted 2006) [#6]
Heh, the same problem lies in the old-old-old ODE wrapper i used in the racer. :D Luckily I dont need to free/recreate everything on a new game loop. JV-ODE sure is a solid peice of kit.