Skip to content

Commit

Permalink
switch dynsystemparam to shared and block it from being used with exc…
Browse files Browse the repository at this point in the history
…lusive parameters
  • Loading branch information
ItsDoot committed Feb 4, 2025
1 parent 2dbfdc8 commit ed7762e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions crates/bevy_ecs/src/system/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
resource::Resource,
system::{
DynSystemParam, DynSystemParamState, Local, ParamSet, Query, SystemMeta, SystemParam,
WorldAccessLevel,
},
world::{
FilteredResources, FilteredResourcesBuilder, FilteredResourcesMut,
Expand Down Expand Up @@ -513,6 +514,11 @@ impl<'a> DynParamBuilder<'a> {
/// Creates a new [`DynParamBuilder`] by wrapping a [`SystemParamBuilder`] of any type.
/// The built [`DynSystemParam`] can be downcast to `T`.
pub fn new<T: SystemParam + 'static>(builder: impl SystemParamBuilder<T> + 'a) -> Self {
assert_ne!(
T::world_access_level(),
WorldAccessLevel::Exclusive,
"DynSystemParam cannot hold exclusive system parameters"
);
Self(Box::new(|world, meta| {
DynSystemParamState::new::<T>(builder.build(world, meta))
}))
Expand Down
7 changes: 5 additions & 2 deletions crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2825,8 +2825,11 @@ unsafe impl SystemParam for DynSystemParam<'_, '_> {
}

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

Expand Down

0 comments on commit ed7762e

Please sign in to comment.