Hello,
I'm having an issue in Spine when removing listeners while events are still being fired. I've looked through the Spine code and this seems to happen because EventQueue.drain (inside AnimationState) will loop from 0 to the amount of listeners. When a listener is removed during this, the values in the array are shifted, but the iterator remains the same, skipping a listener.
Here's some example code which gives me the error when multiple listeners exist on a spine. Is there a better way to do this or is this a bug?
eventToPromise<T extends keyof PIXI.spine.core.AnimationStateListener2>(event_: T😞 Promise<void> {
return new Promise((resolve_) => {
const animationStateListener: PIXI.spine.core.AnimationStateListener2 = {
[event_]: () => {
// Only listen once
this.state.removeListener(animationStateListener)
resolve_()
},
}
// Listen for callback
this.state.addListener(animationStateListener)
})
}