diff --git a/crates/bevy_winit/src/state.rs b/crates/bevy_winit/src/state.rs index 56006e56a3e313..8f3761330e312a 100644 --- a/crates/bevy_winit/src/state.rs +++ b/crates/bevy_winit/src/state.rs @@ -240,6 +240,25 @@ impl ApplicationHandler for WinitAppRunnerState { return; }; + // winit sends `WindowEvent::Resized(0)` when minimizing the window on Windows OS, + // but not on the other OSs (See https://github.com/rust-windowing/winit/issues/2015) + // So, ignore those events on Windows to avoid screen aspects calculations panicking + #[cfg(target_os = "windows")] + if matches!( + event, + WindowEvent::Resized(PhysicalSize { + width: 0, + height: 0 + }) + ) { + if let Some(winit_window) = winit_windows.get_window(window) { + if winit_window.is_minimized().unwrap_or(false) { + self.window_event_received = false; + return; + } + } + } + // Allow AccessKit to respond to `WindowEvent`s before they reach // the engine. if let Some(adapter) = access_kit_adapters.get_mut(&window) {