Skip to content

Commit

Permalink
[cpp] Fix NaN in IKConstraint due to fp precision.
Browse files Browse the repository at this point in the history
dd - r * r might result in a negative value, even if dd == r * r, depending on compiler optimizations and operation order.
  • Loading branch information
badlogic committed Aug 6, 2024
1 parent 1716baa commit 853b5ee
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion spine-cpp/spine-cpp/src/spine/IkConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 853b5ee

Please sign in to comment.