Skip to content

Commit ed7762e

Browse files
committed
switch dynsystemparam to shared and block it from being used with exclusive parameters
1 parent 2dbfdc8 commit ed7762e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

crates/bevy_ecs/src/system/builder.rs

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
resource::Resource,
99
system::{
1010
DynSystemParam, DynSystemParamState, Local, ParamSet, Query, SystemMeta, SystemParam,
11+
WorldAccessLevel,
1112
},
1213
world::{
1314
FilteredResources, FilteredResourcesBuilder, FilteredResourcesMut,
@@ -513,6 +514,11 @@ impl<'a> DynParamBuilder<'a> {
513514
/// Creates a new [`DynParamBuilder`] by wrapping a [`SystemParamBuilder`] of any type.
514515
/// The built [`DynSystemParam`] can be downcast to `T`.
515516
pub fn new<T: SystemParam + 'static>(builder: impl SystemParamBuilder<T> + 'a) -> Self {
517+
assert_ne!(
518+
T::world_access_level(),
519+
WorldAccessLevel::Exclusive,
520+
"DynSystemParam cannot hold exclusive system parameters"
521+
);
516522
Self(Box::new(|world, meta| {
517523
DynSystemParamState::new::<T>(builder.build(world, meta))
518524
}))

crates/bevy_ecs/src/system/system_param.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -2825,8 +2825,11 @@ unsafe impl SystemParam for DynSystemParam<'_, '_> {
28252825
}
28262826

28272827
fn world_access_level() -> WorldAccessLevel {
2828-
// TODO: Don't assume exclusive access
2829-
WorldAccessLevel::Exclusive
2828+
// We don't allow users to create DynSystemParam's that hold exclusive
2829+
// params, so we can safely return Shared here. This is technically
2830+
// over-restrictive when storing `WorldAccessLevel::None` params, but we
2831+
// can't conditionally return based on the held state.
2832+
WorldAccessLevel::Shared
28302833
}
28312834
}
28322835

0 commit comments

Comments
 (0)