adam.drake Posted February 1, 2022 Share Posted February 1, 2022 (edited) 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) }) } Edited February 1, 2022 by adam.drake Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.