Skip to content

Commit 7ced533

Browse files
committed
Fix panic when the primary window is closed (#6545)
Issue introduced by #6533. Co-authored-by: devil-ira <[email protected]>
1 parent 4ef192b commit 7ced533

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

crates/bevy_ui/src/focus.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,14 @@ pub fn ui_focus_system(
124124
})
125125
.filter_map(|window_id| windows.get(window_id))
126126
.filter(|window| window.is_focused())
127-
.find_map(|window| window.cursor_position())
127+
.find_map(|window| {
128+
window.cursor_position().map(|mut cursor_pos| {
129+
cursor_pos.y = window.height() - cursor_pos.y;
130+
cursor_pos
131+
})
132+
})
128133
.or_else(|| touches_input.first_pressed_position());
129134

130-
let window_height = windows.primary().height();
131-
132135
// prepare an iterator that contains all the nodes that have the cursor in their rect,
133136
// from the top node to the bottom one. this will also reset the interaction to `None`
134137
// for all nodes encountered that are no longer hovered.
@@ -167,7 +170,7 @@ pub fn ui_focus_system(
167170
// clicking
168171
let contains_cursor = if let Some(cursor_position) = cursor_position {
169172
(min.x..max.x).contains(&cursor_position.x)
170-
&& (min.y..max.y).contains(&(window_height - cursor_position.y))
173+
&& (min.y..max.y).contains(&cursor_position.y)
171174
} else {
172175
false
173176
};

0 commit comments

Comments
 (0)