• Bugs
  • c-spine: crash while changing animation

Pseudo code is:

  1. spAnimationState_update(pAnimationState, frac)
  2. it makes call to spineAnimStateHandler as current animation is ending
  3. here (inside StateHandler) I try to launch new animation with spAnimationState_setAnimationByName

and get crash.

Nate, is it works as designed? We can't change animation from callbacks? Or this is some kind of bug?

Related Discussions
...

Right now, don't do that.
End event is fired when you call setAnimation.
Your crash was likely a stack overflow. It kept calling setAnimation->End->setAnimation->End->setAnimation->End... infinitely.

End is fired when you interrupt an animation. If you know what interrupted it, you should just call setAnimation there, instead of through End.

If you instead meant "end" as in the animation played completely, use the Complete event. That's safe.

I use flag to prevent second call to setAnimationByName, so I call it only once. But somehow, some internal structures deleted twice, and crashing ... Anyway, your hint with Complete event works fine here. Thanks!


Another issue. It looks like Spine Editor plays looped animation with setToSetupPose on every start, but SDK plays without this call, so animation loops look different. This is why I need to call spSkeleton_setToSetupPose+ spAnimationState_apply on Complete event. And this is impossible due to stack overflow. Definitely, something wrong with design of all events ...

Yeah.
In 3.0, you won't have to call setToSetupPose yourself (I think).

But if you want it to do that now, you can handle the AnimationState Start event by calling setToSetupPose.

That has nothing to do with calling setAnimation so there's no danger of it doing the infinite End-setAnimation recursion.

AnimationState Start event does not works here, as it's called only once on start. But I have looped "idle" animation and need to reset to default setupPose on every loop start or end.

Complete is the event to use for every loop. End doesn't fire for every loop.

On the Spine side, you should make sure all your looping animation dopesheet items have keys at time 0 and at the last frame.
That way, you don't have to call setToSetupPose for every loop.
I kinda wish Spine editor had a warning for this. It should be pretty easy to fix, especially now.
Go to the first frame, press Ctrl+Shift+L
Save and export the skeleton.

But you do still need to call it for every new animation. That's where Start is helpful.

Pharan, thanks for support. It's easy to fix on Spine side, but it's too late for me now, as I have about 50 animations and I don't want adjust it once again. I have to make some hack on c++ side, as it's faster. Anyway, I think Spine Editor should play loops same as SDK (now without resetting to setupPose) or SDK should play same as editor. No need for any warnings, just be the same.


Animator is not tech-guy, he just uses Spine Editor, click play with loop, if everything plays fine - animation completed. He should not think about all this "specific features", this is a programmer side to inject animation and be same as on editor side.

I have to disagree. That would introduce more problems for the animator than it's worth.
But I also agree that the animator shouldn't think about that stuff too, which is why I think the editor should act as it does now. What I think it should have (eventually) is the option for the animator to play multiple animations with different timings. That's where disabling the setToSetupPose calls make sense, apart from the programmatic control of bones, which really only makes sense on the engine side.

That's why I was for having AnimationState have the option to call setToSetupPose itself, rather than having to code that part for every project. It should be coming in 3.0, but I already implemented it for Spine-C# for basic cases, because people have been looking for it a lot.

Anyway, for setting in looping animations. Use the Complete event. Doesn't need editing in Spine.