From 3ee7630af5b1cb579acd9049c01264c00e2d7eb2 Mon Sep 17 00:00:00 2001 From: devil-ira Date: Fri, 7 Oct 2022 12:56:11 +0200 Subject: [PATCH 1/3] fix --- crates/bevy_hierarchy/src/child_builder.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/crates/bevy_hierarchy/src/child_builder.rs b/crates/bevy_hierarchy/src/child_builder.rs index e759121daa63d..550a89ccb52a9 100644 --- a/crates/bevy_hierarchy/src/child_builder.rs +++ b/crates/bevy_hierarchy/src/child_builder.rs @@ -1,7 +1,4 @@ -use crate::{ - prelude::{Children, Parent}, - HierarchyEvent, -}; +use crate::{Children, HierarchyEvent, Parent}; use bevy_ecs::{ bundle::Bundle, entity::Entity, @@ -68,12 +65,16 @@ fn update_old_parents(world: &mut World, parent: Entity, children: &[Entity]) { fn remove_children(parent: Entity, children: &[Entity], world: &mut World) { let mut events: SmallVec<[HierarchyEvent; 8]> = SmallVec::new(); - for child in children { - world.entity_mut(*child).remove::(); - events.push(HierarchyEvent::ChildRemoved { - child: *child, - parent, - }); + if let Some(parent_children) = world.get::(parent).map(|c| c.0.clone()) { + for &child in children { + if !parent_children.contains(&child) { + continue; + } + world.entity_mut(child).remove::(); + events.push(HierarchyEvent::ChildRemoved { child, parent }); + } + } else { + return; } push_events(world, events); From 0fec5c9c54e14397206f80bce9f38d5a998cb019 Mon Sep 17 00:00:00 2001 From: devil-ira Date: Fri, 7 Oct 2022 12:59:44 +0200 Subject: [PATCH 2/3] avoid clone --- crates/bevy_hierarchy/src/child_builder.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/bevy_hierarchy/src/child_builder.rs b/crates/bevy_hierarchy/src/child_builder.rs index 550a89ccb52a9..eb325ab258a0d 100644 --- a/crates/bevy_hierarchy/src/child_builder.rs +++ b/crates/bevy_hierarchy/src/child_builder.rs @@ -65,17 +65,21 @@ fn update_old_parents(world: &mut World, parent: Entity, children: &[Entity]) { fn remove_children(parent: Entity, children: &[Entity], world: &mut World) { let mut events: SmallVec<[HierarchyEvent; 8]> = SmallVec::new(); - if let Some(parent_children) = world.get::(parent).map(|c| c.0.clone()) { + if let Some(parent_children) = world.get::(parent) { for &child in children { if !parent_children.contains(&child) { continue; } - world.entity_mut(child).remove::(); events.push(HierarchyEvent::ChildRemoved { child, parent }); } } else { return; } + for event in &events { + if let &HierarchyEvent::ChildRemoved { child, .. } = event { + world.entity_mut(child).remove::(); + } + } push_events(world, events); let mut parent = world.entity_mut(parent); From 6c68a7def6af10ed8f5e7b524fc83563164e8abb Mon Sep 17 00:00:00 2001 From: devil-ira Date: Fri, 7 Oct 2022 13:04:56 +0200 Subject: [PATCH 3/3] meh --- crates/bevy_hierarchy/src/child_builder.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/bevy_hierarchy/src/child_builder.rs b/crates/bevy_hierarchy/src/child_builder.rs index eb325ab258a0d..67f16c555112c 100644 --- a/crates/bevy_hierarchy/src/child_builder.rs +++ b/crates/bevy_hierarchy/src/child_builder.rs @@ -67,10 +67,9 @@ fn remove_children(parent: Entity, children: &[Entity], world: &mut World) { let mut events: SmallVec<[HierarchyEvent; 8]> = SmallVec::new(); if let Some(parent_children) = world.get::(parent) { for &child in children { - if !parent_children.contains(&child) { - continue; + if parent_children.contains(&child) { + events.push(HierarchyEvent::ChildRemoved { child, parent }); } - events.push(HierarchyEvent::ChildRemoved { child, parent }); } } else { return;