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:
akimakinai 2024-09-28 21:30:01 +09:00 committed by GitHub
parent df23b937cc
commit 4a013b687a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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),
)))); ))));
} }