diff options
author | Porteries Tristan <republicthunderbolt9@gmail.com> | 2015-08-11 13:56:57 +0300 |
---|---|---|
committer | Porteries Tristan <republicthunderbolt9@gmail.com> | 2015-08-11 14:02:17 +0300 |
commit | a790e172d0281e64517ff44d80f1c0139c3ab665 (patch) | |
tree | c28248f331bed25db6a4ea22b473cbd831678670 | |
parent | 10dbe966e120632efaae4cbd5c1336fc163e5c07 (diff) |
BGE: Fix T38448: Bullet constraint memory leak.
-rw-r--r-- | source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 53c007f256c..273e7323514 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -537,8 +537,18 @@ bool CcdPhysicsEnvironment::RemoveCcdPhysicsController(CcdPhysicsController* ctr con->getRigidBodyA().activate(); con->getRigidBodyB().activate(); m_dynamicsWorld->removeConstraint(con); + + // The other physics controller in the constraint, can't be NULL. + CcdPhysicsController *otherCtrl = (body == &con->getRigidBodyA()) ? + (CcdPhysicsController *)con->getRigidBodyB().getUserPointer() : + (CcdPhysicsController *)con->getRigidBodyA().getUserPointer(); + + otherCtrl->removeCcdConstraintRef(con); ctrl->removeCcdConstraintRef(con); - //delete con; //might be kept by python KX_ConstraintWrapper + /** Since we remove the constraint in the onwer and the target, we can delete it, + * KX_ConstraintWrapper keep the constraint id not the pointer, so no problems. + */ + delete con; } m_dynamicsWorld->removeRigidBody(ctrl->GetRigidBody()); |