From db0f44b5863ed70ee12214c0fa9b9b6b0f3d0e8e Mon Sep 17 00:00:00 2001 From: Ellen Date: Fri, 4 Mar 2022 01:56:10 +0000 Subject: [PATCH] >:( --- crates/bevy_ecs/src/entity/mod.rs | 6 +++++- crates/bevy_ecs/src/world/mod.rs | 15 +++++++++------ crates/bevy_render/src/lib.rs | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index cedfdbafca203c..86a99132f197e9 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -199,7 +199,7 @@ impl<'a> core::iter::ExactSizeIterator for ReserveEntitiesIterator<'a> {} #[derive(Debug, Default)] pub struct Entities { - pub meta: Vec, + pub(crate) meta: Vec, /// The `pending` and `free_cursor` fields describe three sets of Entity IDs /// that have been freed or are in the process of being allocated: @@ -243,6 +243,10 @@ pub struct Entities { } impl Entities { + pub fn meta_len(&self) -> usize { + self.meta.len() + } + /// Reserve entity IDs concurrently. /// /// Storage for entity generation and location is lazily allocated by calling `flush`. diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 22add5b970365a..edf627678d536d 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -134,18 +134,21 @@ impl World { &self.entities } - /// Retrieves this world's [Entities] collection mutably - #[inline] - pub fn entities_mut(&mut self) -> &mut Entities { - &mut self.entities - } - /// Retrieves this world's [Archetypes] collection #[inline] pub fn archetypes(&self) -> &Archetypes { &self.archetypes } + /// Retrieves this world's [Entities] collection mutably + /// + /// # Safety + /// No funny business + #[inline] + pub unsafe fn entities_mut(&mut self) -> &mut Entities { + &mut self.entities + } + /// Retrieves this world's [Components] collection #[inline] pub fn components(&self) -> &Components { diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index 36f4cbc2925000..7713162f635f71 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -189,7 +189,7 @@ impl Plugin for RenderPlugin { // reserve all existing app entities for use in render_app // they can only be spawned using `get_or_spawn()` - let meta_len = app_world.entities().meta.len(); + let meta_len = app_world.entities().meta_len(); render_app .world .entities() @@ -198,7 +198,7 @@ impl Plugin for RenderPlugin { // flushing as "invalid" ensures that app world entities aren't added as "empty archetype" entities by default // these entities cannot be accessed without spawning directly onto them // this _only_ works as expected because clear_entities() is called at the end of every frame. - render_app.world.entities_mut().flush_as_invalid(); + unsafe { render_app.world.entities_mut() }.flush_as_invalid(); } {