From 4bd56b6da1362f503203b66941bdbec742ec3cd7 Mon Sep 17 00:00:00 2001 From: MiniaczQ Date: Sun, 14 Jul 2024 18:47:28 +0200 Subject: [PATCH] Dirty fix for App hanging when windows are invisible on WindowsOS (#14155) # Objective - Fixes #14135 ## Solution - If no windows are visible, app updates will run regardless of redraw call result. This a relatively dirty fix, a more robust solution is desired in the long run: https://github.com/bevyengine/bevy/issues/1343#issuecomment-770091684 https://discord.com/channels/691052431525675048/1253771396832821270/1258805997011730472 The solution would disconnect rendering from app updates. ## Testing - `window_settings` now works ## Other platforms Not a problem on Linux: https://discord.com/channels/691052431525675048/692572690833473578/1259526650622640160 Not a problem on MacOS: https://discord.com/channels/691052431525675048/692572690833473578/1259563986148659272 --- crates/bevy_winit/src/state.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/bevy_winit/src/state.rs b/crates/bevy_winit/src/state.rs index dcba31bb41..0e8bd74566 100644 --- a/crates/bevy_winit/src/state.rs +++ b/crates/bevy_winit/src/state.rs @@ -504,8 +504,16 @@ impl ApplicationHandler for WinitAppRunnerState { let begin_frame_time = Instant::now(); if should_update { + let (_, windows) = focused_windows_state.get(self.world()); + // If no windows exist, this will evaluate to `true`. + let all_invisible = windows.iter().all(|w| !w.1.visible); + // Not redrawing, but the timeout elapsed. - if !self.ran_update_since_last_redraw { + // + // Additional condition for Windows OS. + // If no windows are visible, redraw calls will never succeed, which results in no app update calls being performed. + // This is a temporary solution, full solution is mentioned here: https://github.com/bevyengine/bevy/issues/1343#issuecomment-770091684 + if !self.ran_update_since_last_redraw || all_invisible { self.run_app_update(); self.ran_update_since_last_redraw = true; } else {