Destroying vehicles dynamically

Please don't post Bullet support questions here, use the above forums instead.
dwells254lb43
Posts: 10
Joined: Wed Jan 21, 2009 12:27 am

Destroying vehicles dynamically

Post by dwells254lb43 »

Hello again. I am having a little bit of a problem in how to dynamically destroy a btraycastingvehicle. The demos are helpful but not doing this, they are destroying everything at the end, not on the fly. What I am doing right now give me some nasty corruption errors or if it does delete it, it has some strange effect on some meshes that have absolutely no correlation.
Any help on how to destroy the vehicles is a plus for me right now.

Here is the ugly way I am doing it right now, and i know its probably horribly wrong..

(*it) is our own vehicle class that holds:
btRigidBody* mVehicleChasis;
btRigidBody* mVehicleWeapon;
btSliderConstraint *mWeaponSlider;
btVehicleRaycaster* mVehicleRaycast;
btRaycastVehicle* mVehicle;

Code: Select all


////////////========================Destroy chassis============================
			{
				btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[(*it)->miID];
				btRigidBody* body = btRigidBody::upcast(obj);
				if (body && body->getMotionState())
				{
					while(body->getNumConstraintRefs())
					{
						btTypedConstraint* constraint = body->getConstraintRef(0);
						dynamicsWorld->removeConstraint(constraint);
						delete constraint;

					}
					delete body->getMotionState();
					dynamicsWorld->removeRigidBody(body);
				}
				else
				{
					dynamicsWorld->removeCollisionObject( obj );
				}
				delete obj;
			}
			//====Destroy weapon====================================
// the weapon body is a slider constraint attached to the chassis
			{
				btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[(*it)->miWeaponID];
				btRigidBody* body = btRigidBody::upcast(obj);
				if (body && body->getMotionState())
				{
					while(body->getNumConstraintRefs())
					{
						btTypedConstraint* constraint = body->getConstraintRef(0);
						dynamicsWorld->removeConstraint(constraint);
						delete constraint;

					}
					delete body->getMotionState();
					dynamicsWorld->removeRigidBody(body);
				}
				else
				{
					dynamicsWorld->removeCollisionObject( obj );
				}
				delete obj;
			}
			dynamicsWorld->removeAction((*it)->mVehicle);//same as removeVehicle
			///////////============================================================



Then in our vehicle object's destructor we have

delete mVehicleRaycast;
delete mVehicle;


any help or rewrite would be helpful.

thank you.
Francescu
Posts: 5
Joined: Tue Apr 07, 2009 6:53 pm

Re: Destroying vehicles dynamically

Post by Francescu »

Hi,

Did you ever solve your corruption issue - am having the same problem at runtime.

Basically, what is the proper way to completely remove rigid bodies from a scene dynamically at runtime (not at the end)?

Thanks in advance.