From 65292fd55929d5f34a270b6c28b95ba3142a5c8c Mon Sep 17 00:00:00 2001 From: NiseVoid Date: Mon, 17 Apr 2023 18:06:00 +0200 Subject: [PATCH] Improve warning for Send resources marked as non_send (#8000) # Objective - Fixes unclear warning when `insert_non_send_resource` is called on a Send resource ## Solution - Add a message to the asssert statement that checks this --------- Co-authored-by: James Liu --- crates/bevy_ecs/src/storage/resource.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/storage/resource.rs b/crates/bevy_ecs/src/storage/resource.rs index f856bf9bb7..9862590ef2 100644 --- a/crates/bevy_ecs/src/storage/resource.rs +++ b/crates/bevy_ecs/src/storage/resource.rs @@ -259,7 +259,7 @@ impl Resources { /// /// # Panics /// Will panic if `component_id` is not valid for the provided `components` - /// If `SEND` is false, this will panic if `component_id`'s `ComponentInfo` is not registered as being `Send` + `Sync`. + /// If `SEND` is true, this will panic if `component_id`'s `ComponentInfo` is not registered as being `Send` + `Sync`. pub(crate) fn initialize_with( &mut self, component_id: ComponentId, @@ -269,7 +269,11 @@ impl Resources { self.resources.get_or_insert_with(component_id, || { let component_info = components.get_info(component_id).unwrap(); if SEND { - assert!(component_info.is_send_and_sync()); + assert!( + component_info.is_send_and_sync(), + "Send + Sync resource {} initialized as non_send. It may have been inserted via World::insert_non_send_resource by accident. Try using World::insert_resource instead.", + component_info.name(), + ); } ResourceData { column: ManuallyDrop::new(Column::with_capacity(component_info, 1)),