Skip to content

Commit 2a0bdc2

Browse files
committed
make script exclusive systems actually exclusive
1 parent 8330c2f commit 2a0bdc2

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

crates/bevy_mod_scripting_core/src/bindings/script_system.rs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ impl<P: IntoScriptPluginParams> System for DynamicScriptSystem<P> {
393393
fn has_deferred(&self) -> bool {
394394
false
395395
}
396+
397+
396398

397399
unsafe fn run_unsafe(
398400
&mut self,
@@ -411,15 +413,21 @@ impl<P: IntoScriptPluginParams> System for DynamicScriptSystem<P> {
411413
};
412414

413415
let mut payload = Vec::with_capacity(state.system_params.len());
414-
415-
let guard = WorldAccessGuard::new_non_exclusive(
416-
world,
417-
state.subset.clone(),
418-
state.type_registry.clone(),
419-
state.allocator.clone(),
420-
state.function_registry.clone(),
421-
state.schedule_registry.clone(),
422-
);
416+
417+
let guard = if self.exclusive {
418+
// safety: we are an exclusive system, therefore the cell allows us to do this
419+
let world = unsafe {world.world_mut()};
420+
WorldAccessGuard::new_exclusive(world)
421+
} else {
422+
WorldAccessGuard::new_non_exclusive(
423+
world,
424+
state.subset.clone(),
425+
state.type_registry.clone(),
426+
state.allocator.clone(),
427+
state.function_registry.clone(),
428+
state.schedule_registry.clone(),
429+
)
430+
};
423431

424432
// TODO: cache references which don't change once we have benchmarks
425433
for param in &mut state.system_params {
@@ -615,6 +623,20 @@ impl<P: IntoScriptPluginParams> System for DynamicScriptSystem<P> {
615623
fn default_system_sets(&self) -> Vec<bevy::ecs::schedule::InternedSystemSet> {
616624
vec![ScriptSystemSet::new(self.name.clone()).intern()]
617625
}
626+
627+
fn type_id(&self) -> TypeId {
628+
TypeId::of::<Self>()
629+
}
630+
631+
632+
fn validate_param(&mut self, world: &World) -> bool {
633+
let world_cell = world.as_unsafe_world_cell_readonly();
634+
self.update_archetype_component_access(world_cell);
635+
// SAFETY:
636+
// - We have exclusive access to the entire world.
637+
// - `update_archetype_component_access` has been called.
638+
unsafe { self.validate_param_unsafe(world_cell) }
639+
}
618640
}
619641

620642

0 commit comments

Comments
 (0)