From 19ee692f9621f89f305096f423507e925b748b9a Mon Sep 17 00:00:00 2001 From: aloucks Date: Thu, 6 Mar 2025 16:13:18 -0500 Subject: [PATCH] Prevent an additional world update after all windows have closed on Windows (#18175) # Objective The fix in #18105 includes a check for running headless, but this allows for an extra world update during shutdown. This commit checks if the `AppExit` event has been recorded and prevents the additional world update. ### Before ``` 2025-03-06T03:11:59.999679Z INFO bevy_window::system: No windows are open, exiting 2025-03-06T03:12:00.001942Z INFO bevy_winit::system: Closing window 0v1 2025-03-06T03:12:00.012691Z INFO bevy_window::system: No windows are open, exiting ``` ### After ``` 2025-03-06T03:18:45.552243Z INFO bevy_window::system: No windows are open, exiting 2025-03-06T03:18:45.554119Z INFO bevy_winit::system: Closing window 0v1 ``` ## Testing Ran `window` examples - `monitor_info` continues to run after all windows are closed (it has `ExitCondition::DontExit`) - `window_settings` invisible window creation works as expected - `multiple_windows` exits after both windows are closed with a single exit message --- crates/bevy_winit/src/state.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/bevy_winit/src/state.rs b/crates/bevy_winit/src/state.rs index 3cc469b62c..35221f5a2e 100644 --- a/crates/bevy_winit/src/state.rs +++ b/crates/bevy_winit/src/state.rs @@ -491,11 +491,12 @@ impl ApplicationHandler for WinitAppRunnerState { { let winit_windows = self.world().non_send_resource::(); let headless = winit_windows.windows.is_empty(); + let exiting = self.app_exit.is_some(); let all_invisible = winit_windows .windows .iter() .all(|(_, w)| !w.is_visible().unwrap_or(false)); - if self.startup_forced_updates > 0 || headless || all_invisible { + if !exiting && (self.startup_forced_updates > 0 || headless || all_invisible) { self.redraw_requested(event_loop); } }