Parcourir la source

Prevent dividing by zero in PhysicsVehicleWheel::update() in cases where elapsedTime is 0.

Adam Blake il y a 13 ans
Parent
commit
35d712b59b
1 fichiers modifiés avec 8 ajouts et 5 suppressions
  1. 8 5
      gameplay/src/PhysicsVehicleWheel.cpp

+ 8 - 5
gameplay/src/PhysicsVehicleWheel.cpp

@@ -212,11 +212,14 @@ void PhysicsVehicleWheel::update(float elapsedTime)
     _host->_node->getMatrix().transformPoint(&wheelPos);
     _host->_node->getMatrix().transformPoint(&wheelPos);
 
 
     // Filter out noise from Bullet
     // Filter out noise from Bullet
-    float dt = elapsedTime / 1000.0f;
-    Vector3 delta = commandedPosition - wheelPos - _positionDelta;
-    float threshold = getStrutRestLength() * 2.0f;
-    float tau = (delta.lengthSquared() > threshold*threshold) ? 0 : 0.06f;
-    _positionDelta += (commandedPosition - wheelPos - _positionDelta) * (dt / (dt + tau));
+    if (elapsedTime > 0.0f)
+    {
+        float dt = elapsedTime / 1000.0f;
+        Vector3 delta = commandedPosition - wheelPos - _positionDelta;
+        float threshold = getStrutRestLength() * 2.0f;
+        float tau = (delta.lengthSquared() > threshold*threshold) ? 0 : 0.06f;
+        _positionDelta += (commandedPosition - wheelPos - _positionDelta) * (dt / (dt + tau));
+    }
 }
 }
 
 
 bool PhysicsVehicleWheel::isFront() const
 bool PhysicsVehicleWheel::isFront() const