Fix physics to not trigger Bullet assert in Debug

When physics attempts to move by a very small amount, precision losses
caused Bullet to trigger an assert in debug from normalizing a zero
length vector.
deque
slothlife 11 years ago
parent 0668019c86
commit 51c45796b1

@ -299,17 +299,33 @@ namespace MWWorld
continue; // velocity updated, calculate nextpos again continue; // velocity updated, calculate nextpos again
} }
// trace to where character would go if there were no obstructions if(!newPosition.positionCloses(nextpos, 0.00000001))
tracer.doTrace(colobj, newPosition, nextpos, engine); {
// trace to where character would go if there were no obstructions
tracer.doTrace(colobj, newPosition, nextpos, engine);
// check for obstructions // check for obstructions
if(tracer.mFraction >= 1.0f) if(tracer.mFraction >= 1.0f)
{
newPosition = tracer.mEndPos; // ok to move, so set newPosition
remainingTime *= (1.0f-tracer.mFraction); // FIXME: remainingTime is no longer used so don't set it?
break;
}
}
else
{ {
newPosition = tracer.mEndPos; // ok to move, so set newPosition // The current position and next position are nearly the same, so just exit.
// Note: Bullet can trigger an assert in debug modes if the positions
// are the same, since that causes it to attempt to normalize a zero
// length vector (which can also happen with nearly identical vectors, since
// precision can be lost due to any math Bullet does internally). Since we
// aren't performing any collision detection, we want to reject the next
// position, so that we don't slowly move inside another object.
remainingTime *= (1.0f-tracer.mFraction); // FIXME: remainingTime is no longer used so don't set it? remainingTime *= (1.0f-tracer.mFraction); // FIXME: remainingTime is no longer used so don't set it?
break; break;
} }
Ogre::Vector3 oldPosition = newPosition; Ogre::Vector3 oldPosition = newPosition;
// We hit something. Try to step up onto it. (NOTE: stepMove does not allow stepping over) // We hit something. Try to step up onto it. (NOTE: stepMove does not allow stepping over)
// NOTE: stepMove modifies newPosition if successful // NOTE: stepMove modifies newPosition if successful

Loading…
Cancel
Save