History

guard against feeding bullet a NaN

Seth Alves committed 11 years ago

Commit fbede0a1 parent 2e5b25b2 files · +43 −0Browse files

Showing the changes to libraries/physics/src/ObjectActionSpring.cpp (1 of 2 files). Show all

Unified · Split

libraries/physics/src/ObjectActionSpring.cpp+23−0
@@ -55,6 +55,17 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) { · 54 unmodified lines
5555
5656 // handle the linear part
5757 if (_positionalTargetSet) {
58+ // check for NaN
59+ if (_positionalTarget.x != _positionalTarget.x ||
60+ _positionalTarget.y != _positionalTarget.y ||
61+ _positionalTarget.z != _positionalTarget.z) {
62+ qDebug() << "ObjectActionSpring::updateActionWorker -- target position includes NaN";
63+ unlock();
64+ lockForWrite();
65+ _active = false;
66+ unlock();
67+ return;
68+ }
5869 glm::vec3 offset = _positionalTarget - bulletToGLM(rigidBody->getCenterOfMassPosition());
5970 float offsetLength = glm::length(offset);
6071 float speed = offsetLength / _linearTimeScale;
@@ -70,6 +81,18 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) { · 9 unmodified lines
7081
7182 // handle rotation
7283 if (_rotationalTargetSet) {
84+ if (_rotationalTarget.x != _rotationalTarget.x ||
85+ _rotationalTarget.y != _rotationalTarget.y ||
86+ _rotationalTarget.z != _rotationalTarget.z ||
87+ _rotationalTarget.w != _rotationalTarget.w) {
88+ qDebug() << "AvatarActionHold::updateActionWorker -- target rotation includes NaN";
89+ unlock();
90+ lockForWrite();
91+ _active = false;
92+ unlock();
93+ return;
94+ }
95+
7396 glm::quat bodyRotation = bulletToGLM(rigidBody->getOrientation());
7497 // if qZero and qOne are too close to each other, we can get NaN for angle.
7598 auto alignmentDot = glm::dot(bodyRotation, _rotationalTarget);