stk.patch 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. # This patch adds some assert statements to catch NANs early
  2. # on, and makes some variables in btRaycastVehicle protected.
  3. # To apply, you might have to use patch -l
  4. Index: src/BulletDynamics/Dynamics/btRigidBody.cpp
  5. ===================================================================
  6. --- src/BulletDynamics/Dynamics/btRigidBody.cpp (revision 10122)
  7. +++ src/BulletDynamics/Dynamics/btRigidBody.cpp (working copy)
  8. @@ -133,6 +133,9 @@
  9. void btRigidBody::setGravity(const btVector3& acceleration)
  10. {
  11. + btAssert(!isnan(acceleration.getX()));
  12. + btAssert(!isnan(acceleration.getY()));
  13. + btAssert(!isnan(acceleration.getZ()));
  14. if (m_inverseMass != btScalar(0.0))
  15. {
  16. m_gravity = acceleration * (btScalar(1.0) / m_inverseMass);
  17. @@ -147,6 +150,8 @@
  18. void btRigidBody::setDamping(btScalar lin_damping, btScalar ang_damping)
  19. {
  20. + btAssert(!isnan(lin_damping));
  21. + btAssert(!isnan(ang_damping));
  22. m_linearDamping = btClamped(lin_damping, (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
  23. m_angularDamping = btClamped(ang_damping, (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
  24. }
  25. @@ -285,6 +290,13 @@
  26. void btRigidBody::setCenterOfMassTransform(const btTransform& xform)
  27. {
  28. + btAssert(!isnan(xform.getOrigin().getX()));
  29. + btAssert(!isnan(xform.getOrigin().getY()));
  30. + btAssert(!isnan(xform.getOrigin().getZ()));
  31. + btAssert(!isnan(xform.getRotation().getX()));
  32. + btAssert(!isnan(xform.getRotation().getY()));
  33. + btAssert(!isnan(xform.getRotation().getZ()));
  34. + btAssert(!isnan(xform.getRotation().getW()));
  35. if (isStaticOrKinematicObject())
  36. {
  37. Index: src/BulletDynamics/Dynamics/btRigidBody.h
  38. ===================================================================
  39. --- src/BulletDynamics/Dynamics/btRigidBody.h (revision 10122)
  40. +++ src/BulletDynamics/Dynamics/btRigidBody.h (working copy)
  41. @@ -21,6 +21,11 @@
  42. #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
  43. #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
  44. +#if defined(WIN32) && !defined(__CYGWIN__)
  45. +# define isnan _isnan
  46. +#endif
  47. +#include <math.h>
  48. +
  49. class btCollisionShape;
  50. class btMotionState;
  51. class btTypedConstraint;
  52. @@ -253,6 +258,9 @@
  53. }
  54. void setLinearFactor(const btVector3& linearFactor)
  55. {
  56. + btAssert(!isnan(linearFactor.getX()));
  57. + btAssert(!isnan(linearFactor.getY()));
  58. + btAssert(!isnan(linearFactor.getZ()));
  59. m_linearFactor = linearFactor;
  60. m_invMass = m_linearFactor*m_inverseMass;
  61. }
  62. @@ -267,6 +275,9 @@
  63. void applyCentralForce(const btVector3& force)
  64. {
  65. + btAssert(!isnan(force.getX()));
  66. + btAssert(!isnan(force.getY()));
  67. + btAssert(!isnan(force.getZ()));
  68. m_totalForce += force*m_linearFactor;
  69. }
  70. @@ -303,22 +314,40 @@
  71. void applyForce(const btVector3& force, const btVector3& rel_pos)
  72. {
  73. + btAssert(!isnan(force.getX()));
  74. + btAssert(!isnan(force.getY()));
  75. + btAssert(!isnan(force.getZ()));
  76. + btAssert(!isnan(rel_pos.getX()));
  77. + btAssert(!isnan(rel_pos.getY()));
  78. + btAssert(!isnan(rel_pos.getZ()));
  79. applyCentralForce(force);
  80. applyTorque(rel_pos.cross(force*m_linearFactor));
  81. }
  82. void applyCentralImpulse(const btVector3& impulse)
  83. {
  84. + btAssert(!isnan(impulse.getX()));
  85. + btAssert(!isnan(impulse.getY()));
  86. + btAssert(!isnan(impulse.getZ()));
  87. m_linearVelocity += impulse *m_linearFactor * m_inverseMass;
  88. }
  89. void applyTorqueImpulse(const btVector3& torque)
  90. {
  91. + btAssert(!isnan(torque.getX()));
  92. + btAssert(!isnan(torque.getY()));
  93. + btAssert(!isnan(torque.getZ()));
  94. m_angularVelocity += m_invInertiaTensorWorld * torque * m_angularFactor;
  95. }
  96. void applyImpulse(const btVector3& impulse, const btVector3& rel_pos)
  97. {
  98. + btAssert(!isnan(impulse.getX()));
  99. + btAssert(!isnan(impulse.getY()));
  100. + btAssert(!isnan(impulse.getZ()));
  101. + btAssert(!isnan(rel_pos.getX()));
  102. + btAssert(!isnan(rel_pos.getY()));
  103. + btAssert(!isnan(rel_pos.getZ()));
  104. if (m_inverseMass != btScalar(0.))
  105. {
  106. applyCentralImpulse(impulse);
  107. @@ -355,11 +384,17 @@
  108. inline void setLinearVelocity(const btVector3& lin_vel)
  109. {
  110. + btAssert(!isnan(lin_vel.getX()));
  111. + btAssert(!isnan(lin_vel.getY()));
  112. + btAssert(!isnan(lin_vel.getZ()));
  113. m_linearVelocity = lin_vel;
  114. }
  115. inline void setAngularVelocity(const btVector3& ang_vel)
  116. {
  117. + btAssert(!isnan(ang_vel.getX()));
  118. + btAssert(!isnan(ang_vel.getY()));
  119. + btAssert(!isnan(ang_vel.getZ()));
  120. m_angularVelocity = ang_vel;
  121. }
  122. Index: src/BulletCollision/CollisionShapes/btCollisionShape.cpp
  123. ===================================================================
  124. --- src/BulletCollision/CollisionShapes/btCollisionShape.cpp (revision 10122)
  125. +++ src/BulletCollision/CollisionShapes/btCollisionShape.cpp (working copy)
  126. @@ -116,4 +116,4 @@
  127. btChunk* chunk = serializer->allocate(len,1);
  128. const char* structType = serialize(chunk->m_oldPtr, serializer);
  129. serializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,(void*)this);
  130. -}
  131. \ No newline at end of file
  132. +}
  133. Index: src/BulletCollision/CollisionDispatch/btCollisionObject.h
  134. ===================================================================
  135. --- src/BulletCollision/CollisionDispatch/btCollisionObject.h (revision 10122)
  136. +++ src/BulletCollision/CollisionDispatch/btCollisionObject.h (working copy)
  137. @@ -16,6 +16,13 @@
  138. #ifndef BT_COLLISION_OBJECT_H
  139. #define BT_COLLISION_OBJECT_H
  140. +#if defined(WIN32) && !defined(__CYGWIN__)
  141. +# define isnan _isnan
  142. +# define isinf(x) (!_finite(x))
  143. +#else
  144. +# include <math.h>
  145. +#endif
  146. +
  147. #include "LinearMath/btTransform.h"
  148. //island management, m_activationState1
  149. @@ -294,6 +301,12 @@
  150. void setWorldTransform(const btTransform& worldTrans)
  151. {
  152. + btAssert(!isnan(worldTrans.getOrigin().getX()));
  153. + btAssert(!isnan(worldTrans.getOrigin().getY()));
  154. + btAssert(!isnan(worldTrans.getOrigin().getZ()));
  155. + btAssert(!isinf(worldTrans.getOrigin().getX()));
  156. + btAssert(!isinf(worldTrans.getOrigin().getY()));
  157. + btAssert(!isinf(worldTrans.getOrigin().getZ()));
  158. m_worldTransform = worldTrans;
  159. }
  160. Index: src/BulletDynamics/Vehicle/btRaycastVehicle.
  161. ===================================================================
  162. --- src/BulletDynamics/Vehicle/btRaycastVehicle.h
  163. +++ src/BulletDynamics/Vehicle/btRaycastVehicle.h
  164. @@ -24,7 +24,7 @@
  165. ///rayCast vehicle, very special constraint that turn a rigidbody into a vehicle.
  166. class btRaycastVehicle : public btActionInterface
  167. {
  168. -
  169. +protected:
  170. btAlignedObjectArray<btVector3> m_forwardWS;
  171. btAlignedObjectArray<btVector3> m_axle;
  172. btAlignedObjectArray<btScalar> m_forwardImpulse;
  173. @@ -56,7 +56,7 @@
  174. btScalar m_maxSuspensionForce;
  175. };
  176. -private:
  177. +protected:
  178. btScalar m_tau;
  179. btScalar m_damping;