diff options
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r-- | ecs/src/lib.rs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs index 452f657..3c517dd 100644 --- a/ecs/src/lib.rs +++ b/ecs/src/lib.rs @@ -75,17 +75,27 @@ impl World /// /// # Panics /// Will panic if mutable internal lock cannot be acquired. + #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] pub fn create_entity<Comps>(&mut self, components: Comps) -> EntityUid where Comps: ComponentSequence + TupleReduce<TypeTransformComponentsToAddedEvents>, Comps::Out: EventSequence, { - let (_, entity_uid) = self + let entity_uid = EntityUid::new_unique(); + + #[allow(unused_variables)] + if let Err(err) = self .data .component_storage .write_nonblock() .expect("Failed to acquire read-write component storage lock") - .push_entity(EntityUid::new_unique(), components.into_vec()); + .push_entity(entity_uid, components.into_vec()) + { + #[cfg(feature = "debug")] + tracing::error!("Failed to create entity: {err}"); + + return entity_uid; + }; for component_added_event_id in <Comps::Out as EventSequence>::ids().iter() { self.emit_event_by_id(*component_added_event_id); @@ -160,6 +170,7 @@ impl World /// /// # Panics /// Will panic if a mutable internal lock cannot be acquired. + #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] pub fn perform_queued_actions(&self) { let mut active_action_queue = match *self.data.action_queue.active_queue.borrow() @@ -187,8 +198,15 @@ impl World .map(|component| component.id()) .collect::<Vec<_>>(); - component_storage_lock - .push_entity(EntityUid::new_unique(), components); + #[allow(unused_variables)] + if let Err(err) = component_storage_lock + .push_entity(EntityUid::new_unique(), components) + { + #[cfg(feature = "debug")] + tracing::error!("Failed to create entity: {err}"); + + continue; + } drop(component_storage_lock); |