Skip to content

Commit

Permalink
ParamSets containing non-send parameters should also be non-send (#…
Browse files Browse the repository at this point in the history
…10211)

# Objective

Fix #10207

## Solution

Mark a `ParamSet`'s `SystemMeta` as non-send if any of its component
parameters are non-send.
  • Loading branch information
JoJoJet authored Oct 21, 2023
1 parent 38e0a80 commit 0716922
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ pub fn impl_param_set(_input: TokenStream) -> TokenStream {
#param::init_state(world, &mut #meta);
let #param = #param::init_state(world, &mut system_meta.clone());
)*
// Make the ParamSet non-send if any of its parameters are non-send.
if false #(|| !#meta.is_send())* {
system_meta.set_non_send();
}
#(
system_meta
.component_access_set
Expand Down
30 changes: 30 additions & 0 deletions crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,4 +1739,34 @@ mod tests {
schedule.add_systems(non_sync_system);
schedule.run(&mut world);
}

// Regression test for https://github.com/bevyengine/bevy/issues/10207.
#[test]
fn param_set_non_send_first() {
fn non_send_param_set(mut p: ParamSet<(NonSend<*mut u8>, ())>) {
let _ = p.p0();
p.p1();
}

let mut world = World::new();
world.insert_non_send_resource(std::ptr::null_mut::<u8>());
let mut schedule = crate::schedule::Schedule::default();
schedule.add_systems((non_send_param_set, non_send_param_set, non_send_param_set));
schedule.run(&mut world);
}

// Regression test for https://github.com/bevyengine/bevy/issues/10207.
#[test]
fn param_set_non_send_second() {
fn non_send_param_set(mut p: ParamSet<((), NonSendMut<*mut u8>)>) {
p.p0();
let _ = p.p1();
}

let mut world = World::new();
world.insert_non_send_resource(std::ptr::null_mut::<u8>());
let mut schedule = crate::schedule::Schedule::default();
schedule.add_systems((non_send_param_set, non_send_param_set, non_send_param_set));
schedule.run(&mut world);
}
}

0 comments on commit 0716922

Please sign in to comment.