Skip to content

Commit

Permalink
Better error message for World::resource_scope (#5727)
Browse files Browse the repository at this point in the history
# Objective

- Fixes #5365 
- The `assert!()` when the resource from `World::resource_scope` is inserted into the world is not descriptive.

## Solution

- Add more context to the assert inside of `World::resource_scope` when the `FnOnce` param inserts the resource.
  • Loading branch information
NathanSWard committed Aug 18, 2022
1 parent 00508d1 commit 00323b3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,10 @@ impl World {
},
};
let result = f(self, value_mut);
assert!(!self.contains_resource::<R>());
assert!(!self.contains_resource::<R>(),
"Resource `{}` was inserted during a call to World::resource_scope.\n\
This is not allowed as the original resource is reinserted to the world after the FnOnce param is invoked.",
std::any::type_name::<R>());

let resource_archetype = self.archetypes.resource_mut();
let unique_components = resource_archetype.unique_components_mut();
Expand Down

0 comments on commit 00323b3

Please sign in to comment.