Skip to content

Commit 07d5769

Browse files
committed
fix order of exit/close window systems (#5558)
# 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
1 parent bd00858 commit 07d5769

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

crates/bevy_window/src/lib.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ pub mod prelude {
2222
}
2323

2424
use bevy_app::prelude::*;
25-
use bevy_ecs::{event::Events, schedule::SystemLabel};
25+
use bevy_ecs::{
26+
event::Events,
27+
schedule::{ParallelSystemDescriptorCoercion, SystemLabel},
28+
};
2629

2730
/// The configuration information for the [`WindowPlugin`].
2831
///
@@ -106,7 +109,10 @@ impl Plugin for WindowPlugin {
106109
}
107110

108111
if settings.exit_on_all_closed {
109-
app.add_system(exit_on_all_closed);
112+
app.add_system_to_stage(
113+
CoreStage::PostUpdate,
114+
exit_on_all_closed.after(ModifiesWindows),
115+
);
110116
}
111117
if settings.close_when_requested {
112118
app.add_system(close_when_requested);

0 commit comments

Comments
 (0)