From ef9b898c2d3b0f17c81dcc45a3535e0e3569ae52 Mon Sep 17 00:00:00 2001 From: aloucks Date: Sun, 2 Mar 2025 13:07:21 -0500 Subject: [PATCH] Fix invisible window creation on Windows (#18105) # Objective Fixes #18027 ## Solution Run `redraw_requested` logic in `about_to_wait` on Windows during initial application startup and when in headless mode ## Testing - Ran `cargo run --example window_settings` to demonstrate invisible window creation worked again and fixes #18027 - Ran `cargo run --example eased_motion` to demonstrate no regression with the fix for #17488 Ran all additional `window` examples. Notes: - The `transparent_window` was not transparent but this appears to have been broken prior to #18004. See: #7544 --- crates/bevy_winit/src/state.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/crates/bevy_winit/src/state.rs b/crates/bevy_winit/src/state.rs index 9b139dec46..525a5f22d3 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,21 @@ 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")] + { + let winit_windows = self.world().non_send_resource::(); + let headless = winit_windows.windows.is_empty(); + 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); + } + } } fn suspended(&mut self, _event_loop: &ActiveEventLoop) {