We're having a curious bug in our game code.. we divide levels into "scenes" with private physics worlds (btDiscreetDynamicsWorlds). When we move actors from one scene to another -- the character, for example -- we want to get his physics data in the form of his btRigidBody, load it into the new scene's physics world, and delete it from the world in the previous scene. We can't destroy the old scene's world because we want to be able to move back. We've set it up like so:
To change scenes:
Code: Select all
void SceneSystem::SetCurrentScene(Scene* scene) {
// Loop through the current scene and pull actors
// out that transfer over
if (mCurrentScene) {
. . .
}
}
mCurrentScene = scene;
GAME->GetPhysicsSystem()->SetPhysicsWorld(mCurrentScene->GetPhysicsWorld());
mCurrentScene->OnLoad();
}
}
SetPhysicsWorld just reassigns the pointer in our updating PhysicsSystem world from the former scene's world to the present one (we use a wrapper class, PhysicsWorld, to hold all the bullet objects):
Code: Select all
void PhysicsSystem::SetPhysicsWorld(PhysicsWorld* physicsWorld) {
mPhysicsWorld = physicsWorld->GetPhysicsWorld();
}
The actors get moved in an AddActor and RemoveActor call, and these just call the relevant bullet methods to add and remove a btRigidBody, like so:
Code: Select all
bool PhysicsWorld::RemovePhysicsObject(PhysicsObject* object) {
if (!object) {
return 0;
}
mPhysicsWorld->removeRigidBody(object->GetBTRigidBody());
return 1;
}
The funny thing is, if we comment out the line that deletes the actor from the old world, everything appears to work fine: the new scene loads, the new physics world is up and running with the transferred actors right there. I've stepped through the code and all the objects are valid all the way through. But if we call that remove method, all the Actor and btRigidBody data will still appear to be good, but the code breaks when we attempt stepSimulation on the new world. Any ideas?