From 9b13f4d99ba2dd5f0bb223064a725512bf4af3f3 Mon Sep 17 00:00:00 2001 From: Michael Hsu Date: Wed, 7 Dec 2022 13:03:44 -0800 Subject: [PATCH 1/5] call clear trackers in App.update for sub apps --- crates/bevy_app/src/app.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index c6613825591ec..435fd6d2b30ce 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -150,8 +150,10 @@ impl App { #[cfg(feature = "trace")] let _bevy_frame_update_span = info_span!("frame").entered(); self.schedule.run(&mut self.world); + for sub_app in self.sub_apps.values_mut() { (sub_app.runner)(&mut self.world, &mut sub_app.app); + sub_app.app.world.clear_trackers(); } } From 25428521494839ed8247058bd402add6db0b5bb9 Mon Sep 17 00:00:00 2001 From: Michael Hsu Date: Wed, 7 Dec 2022 13:52:08 -0800 Subject: [PATCH 2/5] directly call clear_trackers in app.update rather than adding to default schedule --- crates/bevy_app/src/app.rs | 5 ++--- crates/bevy_ecs/src/system/system_param.rs | 5 +---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 435fd6d2b30ce..746619e330557 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -107,9 +107,7 @@ impl Default for App { #[cfg(feature = "bevy_reflect")] app.init_resource::(); - app.add_default_stages() - .add_event::() - .add_system_to_stage(CoreStage::Last, World::clear_trackers); + app.add_default_stages().add_event::(); #[cfg(feature = "bevy_ci_testing")] { @@ -150,6 +148,7 @@ impl App { #[cfg(feature = "trace")] let _bevy_frame_update_span = info_span!("frame").entered(); self.schedule.run(&mut self.world); + self.world.clear_trackers(); for sub_app in self.sub_apps.values_mut() { (sub_app.runner)(&mut self.world, &mut sub_app.app); diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index a10737acad773..5bd1b56348fc1 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -803,10 +803,7 @@ impl<'w, 's, T: FromWorld + Send + 'static> SystemParamFetch<'w, 's> for LocalSt /// note that the `RemovedComponents` list will not be automatically cleared for you, /// and will need to be manually flushed using [`World::clear_trackers`] /// -/// For users of `bevy` itself, this is automatically done in a system added by `MinimalPlugins` -/// or `DefaultPlugins` at the end of each pass of the game loop during the `CoreStage::Last` -/// stage. As such `RemovedComponents` systems should be scheduled after the stage where -/// removal occurs but before `CoreStage::Last`. +/// For users of `bevy` itself, this is automatically done in `bevy_app::App::update`. /// /// # Examples /// From fcbe7b15f01657ada6b318678cc470a5c026923a Mon Sep 17 00:00:00 2001 From: Michael Hsu Date: Wed, 7 Dec 2022 14:21:29 -0800 Subject: [PATCH 3/5] clarify comment --- crates/bevy_ecs/src/system/system_param.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 5bd1b56348fc1..a743cd67b765b 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -803,7 +803,7 @@ impl<'w, 's, T: FromWorld + Send + 'static> SystemParamFetch<'w, 's> for LocalSt /// note that the `RemovedComponents` list will not be automatically cleared for you, /// and will need to be manually flushed using [`World::clear_trackers`] /// -/// For users of `bevy` itself, this is automatically done in `bevy_app::App::update`. +/// For users of `bevy` and `bevy_app`, this is automatically done in `bevy_app::App::update`. /// /// # Examples /// From 1158975096883cffa2b2f2102aa7ee1c9e484975 Mon Sep 17 00:00:00 2001 From: Michael Hsu Date: Wed, 7 Dec 2022 14:39:17 -0800 Subject: [PATCH 4/5] move clear trackers to after sub apps extract --- crates/bevy_app/src/app.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 746619e330557..d88a82059126c 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -148,12 +148,13 @@ impl App { #[cfg(feature = "trace")] let _bevy_frame_update_span = info_span!("frame").entered(); self.schedule.run(&mut self.world); - self.world.clear_trackers(); for sub_app in self.sub_apps.values_mut() { (sub_app.runner)(&mut self.world, &mut sub_app.app); sub_app.app.world.clear_trackers(); } + + self.world.clear_trackers(); } /// Starts the application by calling the app's [runner function](Self::set_runner). From f2dc39ffb9b0a147861d452ff1848823f64d5977 Mon Sep 17 00:00:00 2001 From: Mike Hsu Date: Wed, 7 Dec 2022 19:14:46 -0800 Subject: [PATCH 5/5] add comment on when clear trackers is run for the main world --- crates/bevy_ecs/src/system/system_param.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index a743cd67b765b..ca9c4f14ceb79 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -804,6 +804,8 @@ impl<'w, 's, T: FromWorld + Send + 'static> SystemParamFetch<'w, 's> for LocalSt /// and will need to be manually flushed using [`World::clear_trackers`] /// /// For users of `bevy` and `bevy_app`, this is automatically done in `bevy_app::App::update`. +/// For the main world, [`World::clear_trackers`] is run after the main schedule is run and after +/// `SubApp`'s have run. /// /// # Examples ///