Skip to content

Commit

Permalink
move final apply outside of spawned executor
Browse files Browse the repository at this point in the history
  • Loading branch information
hymm committed Jan 31, 2023
1 parent 5d514fb commit 50cbdd0
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions crates/bevy_ecs/src/schedule_v3/executor/multi_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,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 @@ -198,6 +186,19 @@ impl SystemExecutor for MultiThreadedExecutor {
let executor = executor.instrument(executor_span);
scope.spawn(executor);
});

// Do one final apply buffers after all systems have completed
// SAFETY: all systems have completed, and so no outstanding accesses remain
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();
}
}

Expand Down

0 comments on commit 50cbdd0

Please sign in to comment.