From fbede0a23f56749d2fa7abd07fa1179c3dcc0c3d Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 29 Jun 2015 15:54:24 -0700 Subject: [PATCH] guard against feeding bullet a NaN --- interface/src/avatar/AvatarActionHold.cpp | 20 +++++++++++++++++ libraries/physics/src/ObjectActionSpring.cpp | 23 ++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/interface/src/avatar/AvatarActionHold.cpp b/interface/src/avatar/AvatarActionHold.cpp index c1e2080521..dbeb5c5358 100644 --- a/interface/src/avatar/AvatarActionHold.cpp +++ b/interface/src/avatar/AvatarActionHold.cpp @@ -54,6 +54,22 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) { if (!tryLockForWrite()) { return; } + + // check for NaNs + if (position.x != position.x || + position.y != position.y || + position.z != position.z) { + qDebug() << "AvatarActionHold::updateActionWorker -- target position includes NaN"; + return; + } + if (rotation.x != rotation.x || + rotation.y != rotation.y || + rotation.z != rotation.z || + rotation.w != rotation.w) { + qDebug() << "AvatarActionHold::updateActionWorker -- target rotation includes NaN"; + return; + } + _positionalTarget = position; _rotationalTarget = rotation; unlock(); @@ -145,6 +161,7 @@ QByteArray AvatarActionHold::serialize() { dataStream << _relativePosition; dataStream << _relativeRotation; dataStream << _hand; + dataStream << _linearTimeScale; return ba; } @@ -168,6 +185,9 @@ void AvatarActionHold::deserialize(QByteArray serializedArguments) { dataStream >> _relativePosition; dataStream >> _relativeRotation; dataStream >> _hand; + dataStream >> _linearTimeScale; + _angularTimeScale = _linearTimeScale; + _parametersSet = true; _active = true; diff --git a/libraries/physics/src/ObjectActionSpring.cpp b/libraries/physics/src/ObjectActionSpring.cpp index b3b8536b06..715c0bc4e4 100644 --- a/libraries/physics/src/ObjectActionSpring.cpp +++ b/libraries/physics/src/ObjectActionSpring.cpp @@ -55,6 +55,17 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) { // handle the linear part if (_positionalTargetSet) { + // check for NaN + if (_positionalTarget.x != _positionalTarget.x || + _positionalTarget.y != _positionalTarget.y || + _positionalTarget.z != _positionalTarget.z) { + qDebug() << "ObjectActionSpring::updateActionWorker -- target position includes NaN"; + unlock(); + lockForWrite(); + _active = false; + unlock(); + return; + } glm::vec3 offset = _positionalTarget - bulletToGLM(rigidBody->getCenterOfMassPosition()); float offsetLength = glm::length(offset); float speed = offsetLength / _linearTimeScale; @@ -70,6 +81,18 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) { // handle rotation if (_rotationalTargetSet) { + if (_rotationalTarget.x != _rotationalTarget.x || + _rotationalTarget.y != _rotationalTarget.y || + _rotationalTarget.z != _rotationalTarget.z || + _rotationalTarget.w != _rotationalTarget.w) { + qDebug() << "AvatarActionHold::updateActionWorker -- target rotation includes NaN"; + unlock(); + lockForWrite(); + _active = false; + unlock(); + return; + } + glm::quat bodyRotation = bulletToGLM(rigidBody->getOrientation()); // if qZero and qOne are too close to each other, we can get NaN for angle. auto alignmentDot = glm::dot(bodyRotation, _rotationalTarget);