BGE: Fix T38448: Bullet constraint memory leak.

This commit is contained in:
Porteries Tristan 2015-08-11 12:56:57 +02:00
parent 10dbe966e1
commit a790e172d0
Notes: blender-bot 2023-02-14 11:15:43 +01:00
Referenced by commit 9437acb7f3, BGE: Fix memory leak and crash with certain physic types
Referenced by issue #38448, BGE bullet physics constraint memory leak
1 changed files with 11 additions and 1 deletions

View File

@ -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());