From 1f91d828907241eb40ebebdcb021c8ccdea92d76 Mon Sep 17 00:00:00 2001 From: Aaron Loucks Date: Sat, 1 Mar 2025 09:24:20 -0500 Subject: [PATCH 1/3] Run redraw_requested logic in about_to_wait on Windows during initial application startup. Fixes #18027 --- crates/bevy_winit/src/state.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/bevy_winit/src/state.rs b/crates/bevy_winit/src/state.rs index 9b139dec465bd..f65af625f1a6e 100644 --- a/crates/bevy_winit/src/state.rs +++ b/crates/bevy_winit/src/state.rs @@ -435,8 +435,12 @@ impl ApplicationHandler for WinitAppRunnerState { // https://github.com/bevyengine/bevy/issues/17488 #[cfg(target_os = "windows")] { - self.redraw_requested = true; - self.redraw_requested(_event_loop); + // Have the startup behavior run in about_to_wait, which prevents issues with + // invisible window creation. https://github.com/bevyengine/bevy/issues/18027 + if self.startup_forced_updates == 0 { + self.redraw_requested = true; + self.redraw_requested(_event_loop); + } } } _ => {} @@ -480,6 +484,15 @@ impl ApplicationHandler for WinitAppRunnerState { // The monitor sync logic likely belongs in monitor event handlers and not here. #[cfg(not(target_os = "windows"))] self.redraw_requested(event_loop); + + // Have the startup behavior run in about_to_wait, which prevents issues with + // invisible window creation. https://github.com/bevyengine/bevy/issues/18027 + #[cfg(target_os = "windows")] + { + if self.startup_forced_updates > 0 { + self.redraw_requested(event_loop); + } + } } fn suspended(&mut self, _event_loop: &ActiveEventLoop) { From 83e3108a287f6897a056c9f71904925af6bbd259 Mon Sep 17 00:00:00 2001 From: Aaron Loucks Date: Sat, 1 Mar 2025 10:35:41 -0500 Subject: [PATCH 2/3] Add special case for headless mode to keep redraw_requested logic running in about_to_wait. Fixes monitor_info example. --- crates/bevy_winit/src/state.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/bevy_winit/src/state.rs b/crates/bevy_winit/src/state.rs index f65af625f1a6e..6120f7ac2d5a8 100644 --- a/crates/bevy_winit/src/state.rs +++ b/crates/bevy_winit/src/state.rs @@ -489,7 +489,9 @@ impl ApplicationHandler for WinitAppRunnerState { // invisible window creation. https://github.com/bevyengine/bevy/issues/18027 #[cfg(target_os = "windows")] { - if self.startup_forced_updates > 0 { + let winit_windows = self.world().non_send_resource::(); + let headless = winit_windows.windows.is_empty(); + if self.startup_forced_updates > 0 || headless { self.redraw_requested(event_loop); } } From 0abd439771d255898844d110ff8f1543c20d21eb Mon Sep 17 00:00:00 2001 From: Aaron Loucks Date: Sun, 2 Mar 2025 10:21:49 -0500 Subject: [PATCH 3/3] Check for both invisible and headless in about_to_wait on Windows --- crates/bevy_winit/src/state.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/bevy_winit/src/state.rs b/crates/bevy_winit/src/state.rs index 6120f7ac2d5a8..525a5f22d34c2 100644 --- a/crates/bevy_winit/src/state.rs +++ b/crates/bevy_winit/src/state.rs @@ -491,7 +491,11 @@ impl ApplicationHandler for WinitAppRunnerState { { let winit_windows = self.world().non_send_resource::(); let headless = winit_windows.windows.is_empty(); - if self.startup_forced_updates > 0 || headless { + let all_invisible = winit_windows + .windows + .iter() + .all(|(_, w)| !w.is_visible().unwrap_or(false)); + if self.startup_forced_updates > 0 || headless || all_invisible { self.redraw_requested(event_loop); } }