Skip to content

Commit

Permalink
Improve warning for Send resources marked as non_send (#8000)
Browse files Browse the repository at this point in the history
# 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 <contact@jamessliu.com>
  • Loading branch information
NiseVoid and james7132 authored Apr 17, 2023
1 parent 882c86e commit 65292fd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/bevy_ecs/src/storage/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl<const SEND: bool> Resources<SEND> {
///
/// # 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,
Expand All @@ -269,7 +269,11 @@ impl<const SEND: bool> Resources<SEND> {
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)),
Expand Down

0 comments on commit 65292fd

Please sign in to comment.