-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Bevy UI example does not exit when window is closed. #5384
Comments
It happens only for bevy/crates/bevy_winit/src/lib.rs Lines 602 to 611 in 7dcfaae
Therefore The root cause seems to be that the window is removed here bevy/crates/bevy_winit/src/lib.rs Lines 225 to 232 in 7dcfaae
before the event loop can handle the bevy/crates/bevy_winit/src/lib.rs Lines 375 to 385 in 7dcfaae
This workaround seems to work for me, but it feels like a hack and not robust enough. There's probably a cleaner solution as the event loop just needs to run for the diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs
index 135ad332..47bf9882 100644
--- a/crates/bevy_winit/src/lib.rs
+++ b/crates/bevy_winit/src/lib.rs
@@ -331,6 +331,7 @@ pub fn winit_runner_with(mut app: App) {
.0;
let mut app_exit_event_reader = ManualEventReader::<AppExit>::default();
let mut redraw_event_reader = ManualEventReader::<RequestRedraw>::default();
+ let mut window_closed_reader = ManualEventReader::<WindowClosed>::default();
let mut winit_state = WinitPersistentState::default();
app.world
.insert_non_send_resource(event_loop.create_proxy());
@@ -608,6 +609,13 @@ pub fn winit_runner_with(mut app: App) {
winit_state.low_power_event
|| winit_state.redraw_request_sent
|| winit_state.timeout_reached
+ || app
+ .world
+ .get_resource::<Events<WindowClosed>>()
+ .and_then(|window_closed_events| {
+ window_closed_reader.iter(window_closed_events).last()
+ })
+ .is_some()
}
}
} else { |
# Objective Fixes bevyengine#5384 and maybe other issues around window closing/app not exiting ## Solution There are three systems involved in exiting when closing a window: - `close_when_requested` asking Winit to close the window in stage `Update` - `exit_on_all_closed` exiting when no window remains opened in stage `Update` - `change_window` removing windows that are closed in stage `PostUpdate` This ordering meant that when closing a window, we had to run one more frame to actually exit. As there was no window, panics could occur in systems assuming there was a window. In case of Bevy app using a low power options, that means waiting for the timeout before actually exiting the app (60 seconds by default) This PR changes the ordering so that `exit_on_all_closed` happens after `change_window` in the same frame, so there isn't an extra frame without window
# Objective Fixes bevyengine#5384 and maybe other issues around window closing/app not exiting ## Solution There are three systems involved in exiting when closing a window: - `close_when_requested` asking Winit to close the window in stage `Update` - `exit_on_all_closed` exiting when no window remains opened in stage `Update` - `change_window` removing windows that are closed in stage `PostUpdate` This ordering meant that when closing a window, we had to run one more frame to actually exit. As there was no window, panics could occur in systems assuming there was a window. In case of Bevy app using a low power options, that means waiting for the timeout before actually exiting the app (60 seconds by default) This PR changes the ordering so that `exit_on_all_closed` happens after `change_window` in the same frame, so there isn't an extra frame without window
# Objective Fixes #5384 and maybe other issues around window closing/app not exiting ## Solution There are three systems involved in exiting when closing a window: - `close_when_requested` asking Winit to close the window in stage `Update` - `exit_on_all_closed` exiting when no window remains opened in stage `Update` - `change_window` removing windows that are closed in stage `PostUpdate` This ordering meant that when closing a window, we had to run one more frame to actually exit. As there was no window, panics could occur in systems assuming there was a window. In case of Bevy app using a low power options, that means waiting for the timeout before actually exiting the app (60 seconds by default) This PR changes the ordering so that `exit_on_all_closed` happens after `change_window` in the same frame, so there isn't an extra frame without window
# Objective Fixes bevyengine#5384 and maybe other issues around window closing/app not exiting ## Solution There are three systems involved in exiting when closing a window: - `close_when_requested` asking Winit to close the window in stage `Update` - `exit_on_all_closed` exiting when no window remains opened in stage `Update` - `change_window` removing windows that are closed in stage `PostUpdate` This ordering meant that when closing a window, we had to run one more frame to actually exit. As there was no window, panics could occur in systems assuming there was a window. In case of Bevy app using a low power options, that means waiting for the timeout before actually exiting the app (60 seconds by default) This PR changes the ordering so that `exit_on_all_closed` happens after `change_window` in the same frame, so there isn't an extra frame without window
# Objective Fixes bevyengine#5384 and maybe other issues around window closing/app not exiting ## Solution There are three systems involved in exiting when closing a window: - `close_when_requested` asking Winit to close the window in stage `Update` - `exit_on_all_closed` exiting when no window remains opened in stage `Update` - `change_window` removing windows that are closed in stage `PostUpdate` This ordering meant that when closing a window, we had to run one more frame to actually exit. As there was no window, panics could occur in systems assuming there was a window. In case of Bevy app using a low power options, that means waiting for the timeout before actually exiting the app (60 seconds by default) This PR changes the ordering so that `exit_on_all_closed` happens after `change_window` in the same frame, so there isn't an extra frame without window
Bevy version
Bevy Main 7dcfaae
What you did
What went wrong
When closing the window, the bevy app continues to run even after the window is closed.
Additional information
Seems to be related to using
WinitSettings::desktop_app()
. If I comment this out the app exits as expected.The text was updated successfully, but these errors were encountered: