Skip to content

Commit

Permalink
Make InputFocus optional in bevy_winit (#17358)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
IceSentry authored Jan 14, 2025
1 parent 0222b35 commit 41fd280
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/bevy_winit/src/accessibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn should_update_accessibility_nodes(

fn update_accessibility_nodes(
mut adapters: NonSendMut<AccessKitAdapters>,
focus: Res<InputFocus>,
focus: Option<Res<InputFocus>>,
primary_window: Query<(Entity, &Window), With<PrimaryWindow>>,
nodes: Query<(
Entity,
Expand All @@ -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
Expand Down

0 comments on commit 41fd280

Please sign in to comment.