diff --git a/crates/bevy_render/src/view/window/cursor.rs b/crates/bevy_render/src/view/window/cursor.rs index df825ecb6c..8f40ab5016 100644 --- a/crates/bevy_render/src/view/window/cursor.rs +++ b/crates/bevy_render/src/view/window/cursor.rs @@ -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, 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), )))); }