-
Notifications
You must be signed in to change notification settings - Fork 920
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
Use Window.requestIdleCallback()
#2880
Use Window.requestIdleCallback()
#2880
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of thing might want to be configurable. As in, in the event loop constructor for web, add an option for whether or not to use this or the animation frame.
I would rather not, that would push users towards using |
Yeah, the vsync source is |
The current master i have error in console (Chrome + firefox on mac):
Not sure what the error means. My canvas is spawned by winit itself, and not manually. might be because of setting up wgpu surface when calling: i am not sure how it relates to this PR, but #2878 is working for me (rev = ed14254) |
You always have to check if the window size isn't zero yourself, Winit doesn't offer any guarantees in this regard, this is an issue with other backends as well. We are tracking solutions for this here: #2863. But it will require some further design work. |
I think this change causes the loop to pause due to inactivity (or spuriously) on chrome based browsers, or at least the game loop keeps stopping until there's input / or randomly when embedded in itch.io for example |
I think that's expected, you should use However which control flow mode are you using? Is it |
i am using poll and i tried requesting redraws but that did not change anything -- it is for a typical gameloop |
Well, you'd have to wait for #2896 merge, so the |
i see thank you, for now setting controlflow to wait for a zero duration seems to do it (though ignoring vsync on web) until the fix lands |
@GloopShlugger how long are these pauses? Do you have to do anything to induce them? I can't seem to reproduce this on Chrome nor Firefox. |
i have found it to only happen on chrome-based browsers embedded inside an iframe like itch.io, i have also seen it happen with just the dev console open. The way i detected it is by printing every frame and after a while (which has not been a consistent amount) it just stops updating, with or without input. It also on startup seems to run the eventloop once, and then wait for input events like mouse clicks or just moving the mouse seems to trigger a rerun, at which point it runs the loop again for a bit until it just stops. I feel like this is 10000% a browser implementation choice like some sort of powersaving measure chrome does, i may be able to provide an itch.io build if required |
That is unfortunate indeed. I always knew The proper solution is to use the Prioritized Task Scheduling API, unfortunately this isn't available in Firefox/Safari yet. I had another idea that might fix this issue: I will make a PR and ping you. |
interesting i'll definitelly try it, i did end up changing the wait to be reasonable like 5ms in the loop. I do think it would likely end up being fine once / if the update and draw split happens. The other easy short term solution is just forking winit and changing it back to requestanimationframe which isn't that big of a change |
In #2896 we changed |
oh my god it landed and i didn't even notice i'll try that first and see if it changes anything |
I tried out the newest master and with |
@GloopShlugger this doesn't sound right, Working on a PR to move away from |
@daxpedda it does get stuck immediately and the first frame does not get drawn on chrome until you press something. it will be interesting to see if moving away from |
Are you sure that |
I'm calling it from inside the |
Would you mind running a simple JS script in the background to figure out whether this is really a Winit bug or not? const fun = () => {
console.log('rAF callback')
requestAnimationFrame(fun)
}
requestAnimationFrame(fun) |
when this runs in the background the issue is fixed :,) |
??? EDIT: or maybe it's really a bug in Winit, will continue to investigate. |
i will try the PR the moment you ping me and i see it, I hope there's some solution that works with winits model, thank you again for looking into it -- dancing in the pits of web api hell |
I spent a lot of time going through the implementation, but I think there is just something weird going with Chrome, I can't find anything wrong with Winit. If you ever figure out a minimal reproducable example please hit me up, it's hard to debug this without being able to try it. In any case, see #3044. |
This PR replaces the use of
Window.requestAnimationFrame
withWindow.requestIdleCallback
, which is in line with whatControlFlow::Poll
is supposed to be:This is going to make
ControlFlow::Poll
very fast, which is much closer to how other backends work, but it is also gonna consume way more power, which may or may not be desired considering this is Web and running in the browser.I think a lot of people are using
RedrawRequested
as a VSync source, which it is not as far as I understand. See #2412 for that.Reverts #1519.
Related #1305.