Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With multiple tweens, calling stop on any of them from within their onComplete callback causes other tweens to never complete #337

Closed
lmeikle opened this issue Jun 14, 2017 · 6 comments

Comments

@lmeikle
Copy link

lmeikle commented Jun 14, 2017

Hi

There seems to be an issue regarding calling stop on a tween from inside its onComplete callback

Here is a simple example:
https://jsfiddle.net/mpq3hkhe/3/

I create 2 tweens and start them.
When tween 1 completes, it calls stop on itself. This causes tween 2 to never complete.

(You will notice I have also done an another example which works - simply by putting the call to stop in a timeout.)

I know calling stop on tween 1 is not necessary as it has stopped already, I've just done this to demonstrate the issue quickly.
A real life scenario would more like having a reset function which does loads of stuff including stopping the tween. This reset function can be called mid way through the tween or when the tween completes. Depending on when it is called, it should never have adverse effects on other tweens.

I would like to know whether you think I am wrong in my thinking above, and we must always be very careful not to call stop from the onComplete callback.
Or you agree that there seems to be an issue here, if so I can share with you the local fixes I have for it.

Thanks for your time
Laura

@lmeikle lmeikle changed the title With multiple tweens, calling stop on any of them from within their onComplete callback causes other tweens to complete With multiple tweens, calling stop on any of them from within their onComplete callback causes other tweens to never complete Jun 14, 2017
@chixu
Copy link

chixu commented Jun 15, 2017

same issue found here

@matthewww
Copy link

matthewww commented Jun 15, 2017

...and we must always be very careful not to call stop from the onComplete callback.

I would say so for now Laura.

In my own experiments, I saw that this is fixed by using unique IDs for the tweens within the library (as in the hashset branch). Perhaps this will be merged to master at some point. Rather than doing this though we have just stopped using .stop in onComplete callbacks.

@mikebolt
Copy link
Contributor

It looks like this is the same as #264.

@lmeikle
Copy link
Author

lmeikle commented Jun 16, 2017

Hey Mike

I'm not 100% sure it is.
I believe this issue is caused by:
-stopping a tween which then removes it by splicing it out of the _tweens array
-at the same time the update function is still running iterating over the _tweens array
-as we have changed the size of the _tweens array (by removing something), the loop in the update function misses an element

I'm happy to wait and see if the hastset branch get released at some point, thanks matthewww for your comment.

I've fixed the issue in our local version by just setting the _tween element to null rather than splicing it out, and then the _update function null checks and splices at that point.

Thanks all
Laura

@mikebolt
Copy link
Contributor

I decided to finally merge the "hashset" branch. Please re-download master directly because npm and cdnjs aren't picking up the latest commits.

@lmeikle
Copy link
Author

lmeikle commented Jun 26, 2017

Thanks mike! I can confirm it fixes the issue for me :)

dalisoft added a commit to tweenjs/es6-tween that referenced this issue Jul 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants