Jump to content
Search Community

possible bug with .isActive()

kalreg test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi all,

While making my project i use my own queueing function, which was made with help of this forum. Although it works as expected for most of time it sometimes crashes. It wouldnt be strange if it wouldnt crash in completely random moments.

 

You can check my codepen, here is description what is going on, and later my expectation and where bug possibly exists.

 

WHAT IS GOING ON:

 

1. I create mainAnimation timeline. It will hold information if any added earlier animation is being played. It prevents to play multiple animations in the same moment.

2. I call queue.add(box.move, 100). Add is queue object method for adding both function (first parameter) and parameter (second parameter).

3. queue.add simply adds parameters to an array called queue.array like { fnc: box.move, vars: 100 } and later calls queue.next  

4. queue.next checks if mainAnimation is being played. If so do nothing (wait), otherwise add first animation from queue.array to mainAnimation, and add queue.next to the end od mainAnimation.

5. that loop works as long as there is anything to add.

 

HOW TO RUN INTO BUG

 

As you probably see i added 43 times queue.add(box.move, POSITION) at the end of js file; There is console.log that counts length of array with each queue.next call. It should count from 43 to 0 . Why 43? Just because this bug doesnt happen everytime - sometimes happen, sometimes not, so 43 is just for more chance to run into bug :) What is bug? Watch carefully for countdown if it goes from 43 to 0. If it stops on random number (20, 27, 32 or any other) - you were witness of buggy behaviour. If it doesnt happen when you run it for first time, try second or third... after ten times bug will surely occur.

 

WHAT IS WRONG?

Why does it stop running next and next animation? It should run through all 43 steps to the last one. not stop earlier, and surely it shouldnt sometimes run from 43 to 0, and later from 43 to 25 and so on. The problem is in condition mainAnimation.isActive() - line 20 of codepen. Although duration() is same as time() (check console log) and totalprogress() return 1, isActive return true. 

I expect that if queue.next is added to mainAnimation after calling queue.add it will be called after completion of queue.add. If so there should not be any activity in mainAnimation. Although for most of situatuin it works as intended, sometimes it is not.

 

To be honest i have no idea  why same calls returns different behaviour. Am i missing something or is it in fact a bug? If not, how to correct my function to run animation through all steps - from first to last each time i run my program?

Any ideas from gsap masters of wisdom ? :)

See the Pen wJXbbx?editors=1111 by kalreg (@kalreg) on CodePen

Link to comment
Share on other sites

Probably setting 

 

var mainAnimation = new TimelineMax({autoRemoveChildren: true});
 
fix the issue, but until more tests i wont make this thread solved. However still in my opinion it should work anyways without setting autoRemoveChildren.
Link to comment
Share on other sites

Thanks for your patience - it took a while to track this one down. It had to do with tiny rounding issues in JavaScript that were affecting the isActive() method in VERY rare situations. The playhead had to land within 0.0000001 second of the tween's end time (without going past the end). I made the adjustment in the next release which you can preview (uncompressed) at https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/TweenMax-latest-beta.js

 

Better?

Thanks again for letting us know, and sorry about any inconvenience. 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...