[SOLVED] -Crash in btDynamicWorld w/ delete btRaycastVehicle

fsxfreak
Posts: 10
Joined: Mon Sep 03, 2012 12:09 am

[SOLVED] -Crash in btDynamicWorld w/ delete btRaycastVehicle

Post by fsxfreak »

When I try to delete a specific rigid body using:

Code: Select all

    for (int iii = getGameState()->mDynamicsWorld->getNumCollisionObjects() - 1; iii >= 0; iii--)
    {
        btCollisionObject *obj = getGameState()->mDynamicsWorld->getCollisionObjectArray()[iii];
        btRigidBody *body = btRigidBody::upcast(obj);
        if (obj == mbtCar && body && body->getMotionState())
        {
            getGameState()->mDynamicsWorld->getPairCache()->cleanProxyFromPairs(body->getBroadphaseHandle()
               , getGameState()->mDynamicsWorld->getDispatcher());
            while (body->getNumConstraintRefs())
            {
                btTypedConstraint *constraint = body->getConstraintRef(0);
                getGameState()->mDynamicsWorld->removeConstraint(constraint);
                delete constraint;
            }
            delete body->getMotionState();
            getGameState()->mDynamicsWorld->removeRigidBody(body);
        }
    }
    delete mVehicleRaycaster;
    delete mVehicle;
there is an access violation in btDiscreteDynamicsWorld::updateActions(), where it appears it still tries to update a deleted rigid body.

This seems similar to http://www.bulletphysics.org/Bullet/php ... ?f=9&t=696
Last edited by fsxfreak on Sat Sep 08, 2012 9:15 pm, edited 2 times in total.
fsxfreak
Posts: 10
Joined: Mon Sep 03, 2012 12:09 am

Re: btDynamicsWorld access violation when removing rigid bod

Post by fsxfreak »

I forgot to add, here is the stack trace.

Code: Select all

>	Catreon.exe!btDiscreteDynamicsWorld::updateActions(float timeStep)  Line 614 + 0x2c bytes	C++
 	Catreon.exe!btDiscreteDynamicsWorld::internalSingleStepSimulation(float timeStep)  Line 515	C++
 	Catreon.exe!btDiscreteDynamicsWorld::stepSimulation(float timeStep, int maxSubSteps, float fixedTimeStep)  Line 456 + 0x19 bytes	C++
 	Catreon.exe!GameState::updatePhysics()  Line 579 + 0x42 bytes	C++
Edit: Jeez, again, the second time, I solved it by myself.

Here is the solution for any googlers:

Code: Select all

    delete mVehicleRaycaster;
    getGameState()->mDynamicsWorld->removeAction(mVehicle);    //<----I added this line
    delete mVehicle;