From 41fd280596068a5bb87081ff00ab0e444a7e47a6 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Tue, 14 Jan 2025 00:08:20 -0500 Subject: [PATCH] Make InputFocus optional in bevy_winit (#17358) # Objective - Stop bevy from crashing when losing window focus ## Solution - The InputFocus resource is optional but is accessed unconditionally in bevy_winit. Make it optional. ## Testing - Ran the window_settings example ## Note It's possible this might not be a full fix for the issue, but this stop bevy from crashing. Closes #16961 Closes #17227 --- crates/bevy_winit/src/accessibility.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/bevy_winit/src/accessibility.rs b/crates/bevy_winit/src/accessibility.rs index 8d1c5db0c4..57672ec3b4 100644 --- a/crates/bevy_winit/src/accessibility.rs +++ b/crates/bevy_winit/src/accessibility.rs @@ -181,7 +181,7 @@ fn should_update_accessibility_nodes( fn update_accessibility_nodes( mut adapters: NonSendMut, - focus: Res, + focus: Option>, primary_window: Query<(Entity, &Window), With>, nodes: Query<( Entity, @@ -197,6 +197,9 @@ fn update_accessibility_nodes( let Some(adapter) = adapters.get_mut(&primary_window_id) else { return; }; + let Some(focus) = focus else { + return; + }; if focus.is_changed() || !nodes.is_empty() { // Don't panic if the focused entity does not currently exist // It's probably waiting to be spawned