OSDN Git Service

Have character controller properly clean up objects when deleted
authorryan <>
Wed, 10 Aug 2016 22:39:40 +0000 (22:39 +0000)
committerryan <>
Wed, 10 Aug 2016 22:39:40 +0000 (22:39 +0000)
ogrebullet/Dynamics/include/OgreBulletDynamicsCharacter.h
ogrebullet/Dynamics/src/OgreBulletDynamicsCharacter.cpp

index d91f1b5..5f35b82 100644 (file)
@@ -88,6 +88,8 @@ namespace OgreBulletDynamics
                bool in_world;
                bool collisions_enabled;
                btKinematicCharacterController *m_character;
+               btGhostPairCallback *callback;
+               btConvexShape *capsule;
     };
     // -------------------------------------------------------------------------
     inline DynamicsWorld*       CharacterController::getDynamicsWorld()
index 8fc08b4..03799d0 100644 (file)
@@ -62,8 +62,9 @@ namespace OgreBulletDynamics
                btPairCachingGhostObject* ghost = new btPairCachingGhostObject();
                mObject = ghost;
                mObject->setWorldTransform(startTransform);
-               getDynamicsWorld()->getBulletDynamicsWorld()->getPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
-               btConvexShape* capsule = new btCapsuleShape(width, height);
+               callback = new btGhostPairCallback();
+               getDynamicsWorld()->getBulletDynamicsWorld()->getPairCache()->setInternalGhostPairCallback(callback);
+               capsule = new btCapsuleShape(width, height);
                mObject->setCollisionShape (capsule);
                mObject->setCollisionFlags (btCollisionObject::CF_CHARACTER_OBJECT | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
                mObject->setContactProcessingThreshold(0.0);
@@ -80,6 +81,11 @@ namespace OgreBulletDynamics
     CharacterController::~CharacterController()
     {
                mShapeNode->detachAllObjects();
+               delete m_character;
+               getDynamicsWorld()->getBulletDynamicsWorld()->getPairCache()->setInternalGhostPairCallback(0);
+               delete callback;
+               mObject->setCollisionShape(0);
+               delete capsule;
     }
        void CharacterController::addToWorld()
        {