diff --git a/crates/bevy_ecs/src/schedule_v3/executor/multi_threaded.rs b/crates/bevy_ecs/src/schedule_v3/executor/multi_threaded.rs index 3debba3ac59b41..a752ba97ac5ad7 100644 --- a/crates/bevy_ecs/src/schedule_v3/executor/multi_threaded.rs +++ b/crates/bevy_ecs/src/schedule_v3/executor/multi_threaded.rs @@ -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")] @@ -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(); } }