Skip to content

Commit

Permalink
Use try_insert in on_remove_cursor_icon (#15492)
Browse files Browse the repository at this point in the history
# Objective

- Fixes #15490 introduced in #15094.

## Solution

- Use non-panicking `try_insert`

## Testing

- Closing window with `CursorIcon` no longer crashes after this change
(confirmed with `window_settings` example)
  • Loading branch information
akimakinai authored Sep 28, 2024
1 parent df23b93 commit 4a013b6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/bevy_render/src/view/window/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,10 @@ pub fn update_cursors(

/// Resets the cursor to the default icon when `CursorIcon` is removed.
pub fn on_remove_cursor_icon(trigger: Trigger<OnRemove, CursorIcon>, mut commands: Commands) {
// Use `try_insert` to avoid panic if the window is being destroyed.
commands
.entity(trigger.entity())
.insert(PendingCursor(Some(CursorSource::System(
.try_insert(PendingCursor(Some(CursorSource::System(
convert_system_cursor_icon(SystemCursorIcon::Default),
))));
}
Expand Down

0 comments on commit 4a013b6

Please sign in to comment.