Deleting Bodies After Contact

cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

Deleting Bodies After Contact

Post by cobolt_dink »

I've got the user data of the rigid body pointing towards the class that holds all the game data for my objects. Inside the class I have a status flag if the object is alive or dead. I'm overriding the collision callback and if conditions are right an object will get its alive status set to false. At this point there is no reason to have either the collision data or the object game data around so I want to delete it. In the main loop where I'm rendering the objects after they are rendered I go through the list again and check the alive flag and delete the motion state and collision object. But doing that I get an error and it breaks at in the header to get user data. So when/where are we supposed to delete physics data we no longer need?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Deleting Bodies After Contact

Post by Erwin Coumans »

Don't delete/remove rigid bodies during a callback.

Always remove/delete objects outside of the stepSimulation. Most Bullet demos allow deletion of objects using the <END> key. See Bullet/Demos/OpenGL/DemoApplication.cpp how to implement this.

Hope this helps,
Erwin
cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

Re: Deleting Bodies After Contact

Post by cobolt_dink »

I'm deleting in my render loop after stepSimulation() while looping through the CollisionObjectArray. Is there a better place to do this at?

Setting the user pointer data to null after deleting the class seems to have fixed the issue. It was pointing to data that didn't exist anymore and was trying to access parts of it.