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

Window: Fix live-lock when animationFrame is slow #104

Merged
merged 1 commit into from
Apr 20, 2023

Conversation

Johni0702
Copy link
Contributor

If the window is sufficiently complex, it's possible for the average animationFrame to take so long we'll start falling behind with no way to ever catch up. And the amount of frames we're behind will quickly grow to the point where we'll be spending five seconds in animationFrame before we can get a real frame on the screen.
Or even worse with the old while-loop, we'll be stuck indefinitely because the five seconds check only happens outside the loop and we never get to exit the loop if we never catch up, effectively locking up the game.

To prevent that, we limit the animationFrame calls we make per real frame such that we'll still be able to render approximately 30 real frames per second at the cost of animations slowing down.

If the window is sufficiently complex, it's possible for the average
`animationFrame` to take so long we'll start falling behind with no way to ever
catch up. And the amount of frames we're behind will quickly grow to the point
where we'll be spending five seconds in `animationFrame` before we can get a
real frame on the screen.
Or even worse with the old while-loop, we'll be stuck indefinitely because the
five seconds check only happens outside the loop and we never get to exit the
loop if we never catch up, effectively locking up the game.

To prevent that, we limit the `animationFrame` calls we make per real frame such
that we'll still be able to render approximately 30 real frames per second at
the cost of animations slowing down.
@Johni0702 Johni0702 merged commit 3ffa44f into master Apr 20, 2023
@Johni0702 Johni0702 deleted the fix/animationFrame-live-lock branch April 20, 2023 09:50
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

Successfully merging this pull request may close these issues.

2 participants