Przeglądaj źródła

Fixes memory leak issue #407.

Ken Whatmough 13 lat temu
rodzic
commit
a217f29f09

+ 6 - 2
gameplay/src/PhysicsCollisionShape.cpp

@@ -6,8 +6,8 @@
 namespace gameplay
 namespace gameplay
 {
 {
 
 
-PhysicsCollisionShape::PhysicsCollisionShape(Type type, btCollisionShape* shape)
-    : _type(type), _shape(shape)
+PhysicsCollisionShape::PhysicsCollisionShape(Type type, btCollisionShape* shape, btStridingMeshInterface* meshInterface)
+    : _type(type), _shape(shape), _meshInterface(meshInterface)
 {
 {
     memset(&_shapeData, 0, sizeof(_shapeData));
     memset(&_shapeData, 0, sizeof(_shapeData));
 }
 }
@@ -29,6 +29,10 @@ PhysicsCollisionShape::~PhysicsCollisionShape()
                 }
                 }
                 SAFE_DELETE(_shapeData.meshData);
                 SAFE_DELETE(_shapeData.meshData);
             }
             }
+
+            // Also need to delete the btTriangleIndexVertexArray, if it exists.
+            SAFE_DELETE(_meshInterface);
+
             break;
             break;
         case SHAPE_HEIGHTFIELD:
         case SHAPE_HEIGHTFIELD:
             if (_shapeData.heightfieldData)
             if (_shapeData.heightfieldData)

+ 4 - 1
gameplay/src/PhysicsCollisionShape.h

@@ -227,7 +227,7 @@ private:
     /**
     /**
      * Constructor.
      * Constructor.
      */
      */
-    PhysicsCollisionShape(Type type, btCollisionShape* shape);
+    PhysicsCollisionShape(Type type, btCollisionShape* shape, btStridingMeshInterface* meshInterface = NULL);
 
 
     /** 
     /** 
      * Hidden copy constructor.
      * Hidden copy constructor.
@@ -245,6 +245,9 @@ private:
     // Bullet shape object
     // Bullet shape object
     btCollisionShape* _shape;
     btCollisionShape* _shape;
 
 
+    // Bullet mesh interface for mesh types (NULL otherwise)
+    btStridingMeshInterface* _meshInterface;
+
     // Shape specific cached data
     // Shape specific cached data
     union
     union
     {
     {

+ 2 - 1
gameplay/src/PhysicsController.cpp

@@ -1273,7 +1273,8 @@ PhysicsCollisionShape* PhysicsController::createMesh(Mesh* mesh, const Vector3&
     }
     }
 
 
     // Create our collision shape object and store shapeMeshData in it.
     // Create our collision shape object and store shapeMeshData in it.
-    PhysicsCollisionShape* shape = new PhysicsCollisionShape(PhysicsCollisionShape::SHAPE_MESH, bullet_new<btBvhTriangleMeshShape>(meshInterface, true));
+    PhysicsCollisionShape* shape =
+        new PhysicsCollisionShape(PhysicsCollisionShape::SHAPE_MESH, bullet_new<btBvhTriangleMeshShape>(meshInterface, true), meshInterface);
     shape->_shapeData.meshData = shapeMeshData;
     shape->_shapeData.meshData = shapeMeshData;
 
 
     _shapes.push_back(shape);
     _shapes.push_back(shape);