From 5c6628fe3c0aa91e12436ea4b9a41bc505f0ad18 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Sun, 10 Mar 2024 02:14:33 +0000 Subject: [PATCH] try_insert NoAutomaticBatching (#12396) # Objective fix occasional crash from commands.insert when quickly spawning and despawning skinned/morphed meshes ## Solution use `try_insert` instead of `insert`. if the entity is deleted we don't mind failing to add the `NoAutomaticBatching` marker. --- crates/bevy_pbr/src/render/morph.rs | 2 +- crates/bevy_pbr/src/render/skin.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_pbr/src/render/morph.rs b/crates/bevy_pbr/src/render/morph.rs index 7516bb495b..cdc9c599ea 100644 --- a/crates/bevy_pbr/src/render/morph.rs +++ b/crates/bevy_pbr/src/render/morph.rs @@ -109,6 +109,6 @@ pub fn no_automatic_morph_batching( query: Query, Without)>, ) { for entity in &query { - commands.entity(entity).insert(NoAutomaticBatching); + commands.entity(entity).try_insert(NoAutomaticBatching); } } diff --git a/crates/bevy_pbr/src/render/skin.rs b/crates/bevy_pbr/src/render/skin.rs index 8ad3c35d6e..6a725b546c 100644 --- a/crates/bevy_pbr/src/render/skin.rs +++ b/crates/bevy_pbr/src/render/skin.rs @@ -146,6 +146,6 @@ pub fn no_automatic_skin_batching( query: Query, Without)>, ) { for entity in &query { - commands.entity(entity).insert(NoAutomaticBatching); + commands.entity(entity).try_insert(NoAutomaticBatching); } }