rive-app / rive-cpp

C++ runtime for Rive
MIT License
278 stars 42 forks source link

Fix bad assumptions about state machine animation instances. #330

Closed luigi-rosso closed 2 years ago

luigi-rosso commented 2 years ago

Whenever the StateMachine would encounter an AnimationState it would assume that the corresponding stateInstance would be an AnimationStateInstance. This wasn't always the case as AnimationStates can sometimes not point to an Animation (at edit time this is allowed). At runtime we had thought we could be smart about this and simply return a different "empty" State which doesn't do anything (what we call a SystemState) as the corresponding stateInstance, but this would trigger bad casts which a memory sanitizer helped point out.

The fix applied here is to ensure that those assumptions are valid by returning an AnimationStateInstance with an empty animation, which is exactly how the editor behaves too.

luigi-rosso commented 2 years ago

Updated, thanks @csmartdalton!