Skip to content

Commit

Permalink
Merge pull request #112 from hymm/stage-yeet-commands-fixing
Browse files Browse the repository at this point in the history
Stage yeet commands fixing
  • Loading branch information
alice-i-cecile authored Jan 30, 2023
2 parents 075209e + 6adcafa commit ee7b0a6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
29 changes: 15 additions & 14 deletions crates/bevy_ecs/src/scheduling/executor/multi_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,6 @@ impl SystemExecutor for MultiThreadedExecutor {
self.rebuild_active_access();
}
}

// SAFETY: all systems have completed
let world = unsafe { &mut *world.get() };
apply_system_buffers(&mut self.unapplied_systems, systems, world);

debug_assert!(self.ready_systems.is_clear());
debug_assert!(self.running_systems.is_clear());
debug_assert!(self.unapplied_systems.is_clear());
self.active_access.clear();
self.evaluated_sets.clear();
self.skipped_systems.clear();
self.completed_systems.clear();
};

#[cfg(feature = "trace")]
Expand All @@ -212,6 +200,20 @@ impl SystemExecutor for MultiThreadedExecutor {
scope.spawn(executor);
},
);

// SAFETY: all systems have completed, and so no outstanding accesses remain
let world = unsafe { &mut *world.get() };
// Commands should be applied while on the scope's thread, not the executor's thread
apply_system_buffers(&mut self.unapplied_systems, systems, world);
self.unapplied_systems.clear();

debug_assert!(self.ready_systems.is_clear());
debug_assert!(self.running_systems.is_clear());
debug_assert!(self.unapplied_systems.is_clear());
self.active_access.clear();
self.evaluated_sets.clear();
self.skipped_systems.clear();
self.completed_systems.clear();
}
}

Expand Down Expand Up @@ -468,6 +470,7 @@ impl MultiThreadedExecutor {
if is_apply_system_buffers(system) {
// TODO: avoid allocation
let mut unapplied_systems = self.unapplied_systems.clone();
self.unapplied_systems.clear();
let task = async move {
#[cfg(feature = "trace")]
let system_guard = system_span.enter();
Expand Down Expand Up @@ -560,8 +563,6 @@ fn apply_system_buffers(
let system = unsafe { &mut *systems[system_index].get() };
system.apply_buffers(world);
}

unapplied_systems.clear();
}

fn evaluate_and_fold_conditions(conditions: &mut [BoxedCondition], world: &World) -> bool {
Expand Down
2 changes: 0 additions & 2 deletions crates/bevy_ecs/src/scheduling/executor/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ impl SystemExecutor for SimpleExecutor {
#[cfg(feature = "trace")]
system_span.exit();

#[cfg(feature = "trace")]
let _apply_buffers_span = info_span!("apply_buffers", name = &*name).entered();
system.apply_buffers(world);
}

Expand Down
2 changes: 0 additions & 2 deletions crates/bevy_ecs/src/scheduling/executor/single_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ impl SingleThreadedExecutor {
fn apply_system_buffers(&mut self, schedule: &mut SystemSchedule, world: &mut World) {
for system_index in self.unapplied_systems.ones() {
let system = &mut schedule.systems[system_index];
#[cfg(feature = "trace")]
let _apply_buffers_span = info_span!("apply_buffers", name = &*system.name()).entered();
system.apply_buffers(world);
}

Expand Down

0 comments on commit ee7b0a6

Please sign in to comment.