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
55 55
56 // handle the linear part56 // handle the linear part
57 if (_positionalTargetSet) {57 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 }
58 glm::vec3 offset = _positionalTarget - bulletToGLM(rigidBody->getCenterOfMassPosition());69 glm::vec3 offset = _positionalTarget - bulletToGLM(rigidBody->getCenterOfMassPosition());
59 float offsetLength = glm::length(offset);70 float offsetLength = glm::length(offset);
60 float speed = offsetLength / _linearTimeScale;71 float speed = offsetLength / _linearTimeScale;
@@ -70,6 +81,18 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) { · 9 unmodified lines
70 81
71 // handle rotation82 // handle rotation
72 if (_rotationalTargetSet) {83 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
73 glm::quat bodyRotation = bulletToGLM(rigidBody->getOrientation());96 glm::quat bodyRotation = bulletToGLM(rigidBody->getOrientation());
74 // if qZero and qOne are too close to each other, we can get NaN for angle.97 // if qZero and qOne are too close to each other, we can get NaN for angle.
75 auto alignmentDot = glm::dot(bodyRotation, _rotationalTarget);98 auto alignmentDot = glm::dot(bodyRotation, _rotationalTarget);