Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Stageless: move final apply outside of spawned executor #7445

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions crates/bevy_ecs/src/schedule_v3/executor/multi_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,6 @@ impl SystemExecutor for MultiThreadedExecutor {
self.rebuild_active_access();
}
}

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

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

#[cfg(feature = "trace")]
Expand All @@ -199,6 +186,20 @@ 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(&self.unapplied_systems, systems, world);
self.unapplied_systems.clear();
debug_assert!(self.unapplied_systems.is_clear());

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

Expand Down