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) {