• Bugs
  • [ UNITY 5.4 1f1 ] [ BUG ] ArithmeticException: NAN

Hi guys,

Ever since updating to 5.4 in Unity I've been running into this bug.

Any idea what is causing this?

Thanks,

ArithmeticException: NAN
System.Math.Sign (Single value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Math.cs:485)
Spine.Bone.UpdateWorldTransform (Single x, Single y, Single rotation, Single scaleX, Single scaleY) (at Assets/spine-csharp/Bone.cs:134)
Spine.Bone.Update () (at Assets/spine-csharp/Bone.cs:91)
Spine.Skeleton.UpdateWorldTransform () (at Assets/spine-csharp/Skeleton.cs:143)
Spine.Unity.SkeletonAnimator.Update () (at Assets/spine-unity/SkeletonAnimator.cs:191)

Related Discussions
...
  • Đã chỉnh sửa

This is the most bizarre problem I've seen spine-csharp have yet.
Why would a Unity version would cause NaN to appear in the data flow?
You're also the first to report since 5.4 came out. I've been using it regularly to develop and I've never seen this problem.

There is no reason why the UpdateWorldTransform method should be receiving NaN.

Is there anything about your project you can describe more? Or when this error happens? Are you using binary data? Did you make modifications to the runtime? Did you use unusual scaling values or constraints on your bones? Unusual target platform? Hand-edited json?

6 ngày sau

Hi Pharan,

Is there anything about your project you can describe more? Or when this error happens?
It seems to happen randomly as far as I can tell. But it doesn't happen when I play a standalone version.

Are you using binary data? Did you make modifications to the runtime?
Sorry not sure what these are. I'm not a programmer. 😢 But I know I didn't change anything with Skeleton.cs or SkeletonAnimator.cs.

Did you use unusual scaling values or constraints on your bones?
I used a local scale value of (-1) in the x-axis, when needing to flip the character left and right. But that's through a separate C# script attached to the character. I didn't adjust anything from Skeleton.cs or SkeletonAnimator.cs.. The main character also uses this technique, but he doesn't seem to run into the NaN bug, as far as I've noticed.

Unusual target platform? Hand-edited json?
This bug only occurs when I'm playing off Unity Editor. Standalone builds for PC don't seem to show this bug.

Hand-edited json?
I haven't the faintest idea where to start , to even edit it haha.

I haven't updated this particular character for about a year. So it could be that the latest Unity version isn't compatible with whatever settings this character used, from the older version of Spine? Just a blind hunch...

When I go back to update this character and bring in it into Unity with the latest Spine version, I'll keep you posted on the NaN bug.

strange no one else has run into this bug 🙁

2 tháng sau

Hi, working on 5.4.2f2 here, just ran into this same exception. For me, when I toggled the GameObject active and inactive really rapidly to test some logic on other scripts, sometimes Assets/spine-csharp/AnimationState.cs:298 would start spewing this error non-stop. Toggling it off and on again would stop it happening, but anytime it is toggled off and on it seems to have a chance of happening once more.

Have you tried re-exporting? People reported problems with exports from Spine editor 3.5.34 yesterday.

Hi, I think i found the problem. In AnimationState.SetCurrent, the line

// If not completely mixed in, set mixAlpha so mixing out happens from current mix to zero.
if (from.mixingFrom != null) from.mixAlpha *= Math.Min(from.mixTime / from.mixDuration, 1);

If from.mixTime and from.mixDuration are both zero (somehow, I don't really know), then mixAlpha is NaN, and so on.

Hmm, that line should set current.mixAlpha. Pharan! :angry:

For from.mixingFrom to be non-null and from.mixDuration to be 0, you'd have to be setting a new current animation without having applied the previous one. We have some code to discard animations that were set, not applied, and then replaced, so I'm not really sure how you got in that state.

Still, it doesn't hurt to avoid setting a NaN (mmmm naan) mixAlpha. If mixDuration is 0 then the mix is 1 in this code: float alpha = from.alpha * entry.mixAlpha * (1 - mix), which means mixAlpha gets multiplied by zero so its value doesn't matter. That makes the fix:

if (from.mixingFrom != null && from.mixDuration > 0)
   current.mixAlpha *= Math.min(from.mixTime / from.mixDuration, 1);

Thanks for reporting! :angel:

Weird that it took so long to rear its ugly head.