Browse Source

[cpp] Fix NaN in IKConstraint due to fp precision.

dd - r * r might result in a negative value, even if dd == r * r, depending on compiler optimizations and operation order.
Mario Zechner 1 year ago
parent
commit
853b5ee165
1 changed files with 1 additions and 1 deletions
  1. 1 1
      spine-cpp/spine-cpp/src/spine/IkConstraint.cpp

+ 1 - 1
spine-cpp/spine-cpp/src/spine/IkConstraint.cpp

@@ -213,7 +213,7 @@ void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY
 			r0 = q / c2;
 			r1 = c0 / q;
 			r = MathUtil::abs(r0) < MathUtil::abs(r1) ? r0 : r1;
-			if (r * r <= dd) {
+			if (dd - r * r >= 0) {
 				y = MathUtil::sqrt(dd - r * r) * bendDir;
 				a1 = ta - MathUtil::atan2(y, r);
 				a2 = MathUtil::atan2(y / psy, (r - l1) / psx);