juliangarnier / anime

JavaScript animation engine
https://animejs.com
MIT License
50.42k stars 3.68k forks source link

add limit to `getDuration()` in `spring` function to avoid infinite loops #767

Closed okikio closed 2 years ago

okikio commented 3 years ago

The way the getDuration() method in the spring() function is setup it doesn't have any way of stopping an infinite loop. I added a INTINITE_LOOP_LIMIT of 10,000 to stop possible infinite loop situations.

RafaelKr commented 2 years ago

Shouldn't this be named INFINITE_LOOP_LIMIT (with an f instead of t)?

RafaelKr commented 2 years ago

Also maybe it would be an idea to use Number.MAX_SAFE_INTEGER instead of 10,000?

luni-moon commented 2 years ago

I think there are times people would want an infinite loop though...

(Like if you had a terminal blinking, it could blink the underscore infinitely...)

https://user-images.githubusercontent.com/55695493/149813807-013d3055-33c3-46b5-822d-1b9b3f70982d.mp4

okikio commented 2 years ago

While calculating the spring easing, the for loop can sometimes encounter infinite loops that cause the browser to freeze, I've run into this problem a couple times. I choose 10,000 because it was the value that allowed for the most accurate spring easings while avoiding the browser freezing for extended periods of time.

luni-moon commented 2 years ago

While calculating the spring the for loop can sometimes encounter infinite loops, that cause the browser to freeze, I've run into this problem a couple times.

That is true, but I hope there is an alternative method added, to allow things like my example, to work.

okikio commented 2 years ago

While calculating the spring the for loop can sometimes encounter infinite loops, that cause the browser to freeze, I've run into this problem a couple times.

That is true, but I hope there is an alternative method added, to allow things like my example, to work.

What you're looking for is different from what this pr is aiming to fix, but yeah I agree with you, it would be cool if animejs supported blinking animation

luni-moon commented 2 years ago

While calculating the spring the for loop can sometimes encounter infinite loops, that cause the browser to freeze, I've run into this problem a couple times.

That is true, but I hope there is an alternative method added, to allow things like my example, to work.

What you're looking for is different from what this pr is aiming to fix, but yeah I agree with you, it would be cool if animejs supported blinking animation

Yeah, just making sure it doesn't break what I am using it for lol.

RafaelKr commented 2 years ago

While calculating the spring easing, the for loop can sometimes encounter infinite loops that cause the browser to freeze, I've run into this problem a couple times. I choose 10,000 because it was the value that allowed for the most accurate spring easings while avoiding the browser freezing for extended periods of time.

Could you post the code which freezes the browser please? Maybe there's another solution to the problem.

okikio commented 2 years ago

@RafaelKr There was something wrong with this pr, it seems the branch repo the changes were located in were deleted, so, I had to recreate a new pr. The new pr is #798, I'll close this one, we can continue our conversation there.