mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
Use try_insert
in on_remove_cursor_icon
(#15492)
# 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)
This commit is contained in:
parent
df23b937cc
commit
4a013b687a
1 changed files with 2 additions and 1 deletions
|
@ -166,9 +166,10 @@ pub fn update_cursors(
|
||||||
|
|
||||||
/// Resets the cursor to the default icon when `CursorIcon` is removed.
|
/// Resets the cursor to the default icon when `CursorIcon` is removed.
|
||||||
pub fn on_remove_cursor_icon(trigger: Trigger<OnRemove, CursorIcon>, mut commands: Commands) {
|
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
|
commands
|
||||||
.entity(trigger.entity())
|
.entity(trigger.entity())
|
||||||
.insert(PendingCursor(Some(CursorSource::System(
|
.try_insert(PendingCursor(Some(CursorSource::System(
|
||||||
convert_system_cursor_icon(SystemCursorIcon::Default),
|
convert_system_cursor_icon(SystemCursorIcon::Default),
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue