remove character from PhysicsEngine on shutdown

This commit is contained in:
Andrew Meadows 2015-03-30 15:51:58 -07:00
parent 10af59296d
commit 9b13f186e3
3 changed files with 20 additions and 2 deletions

View file

@ -608,6 +608,7 @@ Application::~Application() {
Menu::getInstance()->deleteLater();
_physicsEngine.setCharacterController(NULL);
_myAvatar = NULL;
ModelEntityItem::cleanupLoadedAnimations();

View file

@ -241,6 +241,12 @@ CharacterController::CharacterController(AvatarData* avatarData) {
}
CharacterController::~CharacterController() {
delete _ghostObject;
_ghostObject = NULL;
delete _convexShape;
_convexShape = NULL;
// make sure you remove this Character from its DynamicsWorld before reaching this spot
assert(_dynamicsWorld == NULL);
}
btPairCachingGhostObject* CharacterController::getGhostObject() {

View file

@ -28,6 +28,9 @@ PhysicsEngine::PhysicsEngine(const glm::vec3& offset)
}
PhysicsEngine::~PhysicsEngine() {
if (_characterController) {
_characterController->setDynamicsWorld(NULL);
}
// TODO: delete engine components... if we ever plan to create more than one instance
delete _collisionConfig;
delete _collisionDispatcher;
@ -614,10 +617,18 @@ bool PhysicsEngine::updateObjectHard(btRigidBody* body, ObjectMotionState* motio
}
void PhysicsEngine::setCharacterController(CharacterController* character) {
if (!_characterController) {
if (_characterController != character) {
lock();
_characterController = character;
if (_characterController) {
// remove the character from the DynamicsWorld immediately
_characterController->setDynamicsWorld(NULL);
_characterController = NULL;
}
unlock();
if (character) {
// the character will be added to the DynamicsWorld later
_characterController = character;
}
}
}