Browse Source

Fixed crash related to incorrect constraint reference tracking.

Lasse Öörni 13 years ago
parent
commit
c554abccb8

+ 3 - 0
Engine/Physics/CollisionShape.cpp

@@ -669,7 +669,10 @@ void CollisionShape::UpdateShape()
         }
         
         if (shape_)
+        {
+            shape_->setUserPointer(this);
             shape_->setMargin(margin_);
+        }
         
         cachedWorldScale_ = newWorldScale;
     }

+ 1 - 0
Engine/Physics/Constraint.cpp

@@ -337,6 +337,7 @@ void Constraint::CreateConstraint()
         otherBody_->AddConstraint(this);
     
     ApplyLimits();
+    
     physicsWorld_->GetWorld()->addConstraint(constraint_, disableCollision_);
 }
 

+ 3 - 2
Engine/Physics/RigidBody.cpp

@@ -706,9 +706,10 @@ void RigidBody::ReleaseBody()
     if (body_)
     {
         // Release all constraints which refer to this body
-        for (PODVector<Constraint*>::Iterator i = constraints_.Begin(); i != constraints_.End(); ++i)
+        // Make a copy for iteration
+        PODVector<Constraint*> constraints = constraints_;
+        for (PODVector<Constraint*>::Iterator i = constraints.Begin(); i != constraints.End(); ++i)
             (*i)->ReleaseConstraint();
-        constraints_.Clear();
         
         if (physicsWorld_)
         {