my explosion code causes game to crash

Post Reply
Posts: 8
Joined: Sun Apr 15, 2012 3:34 pm

my explosion code causes game to crash

Post by PgrAm »

I wrote some code to create an explosion and I seem to be having some trouble with it. When it is used it causes the game to crash. I assumed this was because I was trying to upcast a btRigidBody from a btCollsionObject that didn't have one. I check to see if the object is static or not but maybe that's not enough. Here is my code:

Code: Select all

void explodeAtPos(const btVector3& pos, float force, float radius)
	btGhostObject* explosionRadius = new btPairCachingGhostObject();

	btCollisionShape* explosionshape = new btSphereShape(radius);

	explosionRadius->setCollisionFlags(explosionRadius->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);

	dynamicsWorld->addCollisionObject(explosionRadius, btBroadphaseProxy::SensorTrigger, btBroadphaseProxy::AllFilter);

	btTransform explosionTrans;


	for(int i = 0; i < explosionRadius->getOverlappingPairs().size(); i++)
			btCollisionObject* forcedObject = explosionRadius->getOverlappingPairs().at(i);

			btTransform forcedTrans = forcedObject->getWorldTransform();

			btVector3 forceDirection = forcedTrans.getOrigin() - pos;


			btRigidBody::upcast(forcedObject)->applyCentralImpulse(forceDirection*force); //problem is here, commenting out this line prevents crash

	delete explosionRadius;
	delete explosionshape;
the problem seems to be where I upcast to a btRigidBody and apply an impulse to it. If anyone can give any insight on what might be wrong with it I would be infinitely thankful.
Post Reply