diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp index ebe679c449d..79cba4586b7 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp @@ -26,6 +26,7 @@ btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rb m_breakingImpulseThreshold(SIMD_INFINITY), m_isEnabled(true), m_needsFeedback(false), + m_isValid(true), m_overrideNumSolverIterations(-1), m_rbA(rbA), m_rbB(getFixedBody()), @@ -42,6 +43,7 @@ btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rb m_breakingImpulseThreshold(SIMD_INFINITY), m_isEnabled(true), m_needsFeedback(false), + m_isValid(true), m_overrideNumSolverIterations(-1), m_rbA(rbA), m_rbB(rbB), diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.h index d30f3dee5c5..eb0ed2942bc 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.h @@ -84,6 +84,7 @@ btTypedConstraint : public btTypedObject btScalar m_breakingImpulseThreshold; bool m_isEnabled; bool m_needsFeedback; + bool m_isValid; int m_overrideNumSolverIterations; btTypedConstraint& operator=(btTypedConstraint& other) @@ -198,6 +199,18 @@ public: m_breakingImpulseThreshold = threshold; } + bool isValid() const{ + return m_isValid; + } + + void invalidate(){ + if(isValid()){ + m_rbA.removeConstraintRef(this); + m_rbB.removeConstraintRef(this); + m_isValid = false; + } + } + bool isEnabled() const { return m_isEnabled; diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp b/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp index fb15ae31eb5..3a93b264645 100644 --- a/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp +++ b/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp @@ -530,6 +530,10 @@ void btDiscreteDynamicsWorld::removeCollisionObject(btCollisionObject* collision void btDiscreteDynamicsWorld::removeRigidBody(btRigidBody* body) { + for (int i = body->getNumConstraintRefs() - 1; i >= 0; i--) { + btTypedConstraint *con=body->getConstraintRef(i); + removeConstraint(con); + } m_nonStaticRigidBodies.remove(body); btCollisionWorld::removeCollisionObject(body); } @@ -644,8 +648,7 @@ void btDiscreteDynamicsWorld::addConstraint(btTypedConstraint* constraint, bool void btDiscreteDynamicsWorld::removeConstraint(btTypedConstraint* constraint) { m_constraints.remove(constraint); - constraint->getRigidBodyA().removeConstraintRef(constraint); - constraint->getRigidBodyB().removeConstraintRef(constraint); + constraint->invalidate(); } void btDiscreteDynamicsWorld::addAction(btActionInterface* action)