-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix: rewrite winit loop #12669
fix: rewrite winit loop #12669
Conversation
Does this also fix #12106? |
I don't have a Windows machine unfortunately. I tested these successfully on MacOS:
|
I tested this on my M1 Macbook, both by using |
@pietrosophya I've added a section on platform-specific testing to the PR description: please feel free to update the checklist as reviewer reports come in :) |
@alice-i-cecile thank you! I also tested WASM on both Chrome and Firefox, do I have to update the list or is it for reviewers only to check platforms off? |
Go ahead and check this off yourself :) I've also added Safari: I forgot that its web support is also different and weird. |
wasm/webgl2 support is mostly the same across browsers for the event loop, but wasm/webgpu needs to be tested too |
Tested on windows 11 with most of the window example. Seems to work fine. |
Tested every example relating to windows and a few other ones on Linux with X11 and XMonad, no issues found. |
Tested the window examples on Linux with Wayland and Sway, with the Wayland feature enabled and disabled: Only issue i noticed was transparent_window not working when the Wayland feature is enabled, but the issue is the same on main / 13.1, was also mentioned in #10929 already. Noticed no issues from this pr. |
I fixed the suspension in Android, I had to test it on a previous forked version because of this. I took another refactoring opportunity and moved some comments to clarify them. @eero-lehtinen could you try android again? |
It works perfectly for me now on Android. |
Tested on the iOS emulator, it works well (suspending and resuming music too). |
winit 0.30 was released, so maybe we need more rewrites :D |
looks OK to me, except for an enum name. Could you change it and resolve conflicts? @Maximetinu I'm requesting a new review as the PR changed, please re-review if you can |
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.
@Maximetinu I'm requesting a new review as the PR changed, please re-review if you can
Done! It still LGTM, approved ✅
There are some more ideas to clean up this part of the code that I think are interesting to consider, but they may be out of scope for this PR, specially if we don't want to introduce breaking changes:
-
The difference between UpdateModes
Reactive
andReactiveLowPower
is only the kind of events (window and/or device) that should trigger an update, so we could merge them into a singleReactive
, with 2 booleans to expose this customizability. Maybe evenContinuous
could eventually converge into the same type as well. To keep the same current simplicity to the user, we could expose 2 different constructors forUpdateMode
:UpdateMode::reactive()
andUpdateMode::reactive_low_power()
in the same way we haveWinitSettings::desktop_app()
andWinitSettings::game()
. The reason for this is that the user may not want to update due to window or device events at all, so the update is controlled manually in some other way, like from an external host app by a request redraw user event through the event loop proxy. -
The fact that the
UserEvent
of the Event Loop Proxy is namedRequestRedraw
makes it easy to confuse with theWindowEvent::RedrawRequested
. I often mix that one up withEvent::UserEvent(RequestRedraw)
. In fact, since theRequestRedraw
event can now be sent through the Event Loop Proxy, should it still be an ECS event at all? From the user POV, we now have 2 different ways to request a redraw: through the proxy or through the ECS command, and it's unclear to me if the 2 are exactly the same or not. But I don't have an strong opinion on how to solve this or make this clearer tbh.
@mockersf I resolved conflicts and changed the name. I'll create another PR after this is merged to make this new |
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.
I'm happy with the improvements to code quality and bug fixes here, and think this is adequately tested. I'm going to leave an approval and get this merged no later than next Monday to ensure that it gets into the hands of folks to test.
https://github.com/bevyengine/bevy/actions/runs/8929016345/job/24525847476 @pietrosophya once that's fixed ping me and I'll retry the merge. |
@alice-i-cecile argh, sorry about that, it's fixed now. |
Objective
Solution
The Winit loop runs following this flow:
Bevy also uses the UpdateMode, to define how the next loop has to run. It can be essentially:
The changes are made to follow this pattern, so that
To make the code more logical:
Platform-specific testing