From 51c45796b183a5b4d71323602045674a0c4be71c Mon Sep 17 00:00:00 2001 From: slothlife Date: Sat, 7 Jun 2014 19:26:12 -0500 Subject: [PATCH] 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. --- apps/openmw/mwworld/physicssystem.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index b0b00c6db..fde774662 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -299,17 +299,33 @@ namespace MWWorld continue; // velocity updated, calculate nextpos again } - // trace to where character would go if there were no obstructions - tracer.doTrace(colobj, newPosition, nextpos, engine); + if(!newPosition.positionCloses(nextpos, 0.00000001)) + { + // trace to where character would go if there were no obstructions + tracer.doTrace(colobj, newPosition, nextpos, engine); - // check for obstructions - if(tracer.mFraction >= 1.0f) + // check for obstructions + 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? break; } + Ogre::Vector3 oldPosition = newPosition; // We hit something. Try to step up onto it. (NOTE: stepMove does not allow stepping over) // NOTE: stepMove modifies newPosition if successful