Skip to content

Commit 4a013b6

Browse files
authored
Use try_insert in on_remove_cursor_icon (bevyengine#15492)
# Objective - Fixes bevyengine#15490 introduced in bevyengine#15094. ## Solution - Use non-panicking `try_insert` ## Testing - Closing window with `CursorIcon` no longer crashes after this change (confirmed with `window_settings` example)
1 parent df23b93 commit 4a013b6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

crates/bevy_render/src/view/window/cursor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ pub fn update_cursors(
166166

167167
/// Resets the cursor to the default icon when `CursorIcon` is removed.
168168
pub fn on_remove_cursor_icon(trigger: Trigger<OnRemove, CursorIcon>, mut commands: Commands) {
169+
// Use `try_insert` to avoid panic if the window is being destroyed.
169170
commands
170171
.entity(trigger.entity())
171-
.insert(PendingCursor(Some(CursorSource::System(
172+
.try_insert(PendingCursor(Some(CursorSource::System(
172173
convert_system_cursor_icon(SystemCursorIcon::Default),
173174
))));
174175
}

0 commit comments

Comments
 (0)