From 29f711cd408283709182788402db0c4dbe761b01 Mon Sep 17 00:00:00 2001 From: ickk Date: Sat, 18 Nov 2023 23:53:09 +1100 Subject: [PATCH] add regression test for #10385/#10389 (#10609) Bevy introduced unintentional breaking behaviour along with the v0.12.0 release regarding the `App::set_runner` API. See: #10385, #10389 for details. We weren't able to catch this before release because this API is only used internally in one or two places (the very places which motivated the break). This commit adds a regression test to help guarantee some expected behaviour for custom runners, namely that `app::update` won't be called before the runner has a chance to initialise state. --- crates/bevy_app/src/app.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 296ab0c7c4..ee2b431996 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -1204,4 +1204,36 @@ mod tests { GenericLabel::(PhantomData).intern() ); } + + /// Custom runners should be in charge of when `app::update` gets called as they may need to + /// coordinate some state. + /// bug: + /// fix: + #[test] + fn regression_test_10385() { + use super::{Res, Resource}; + use crate::PreUpdate; + + #[derive(Resource)] + struct MyState {} + + fn my_runner(mut app: App) { + let my_state = MyState {}; + app.world.insert_resource(my_state); + + for _ in 0..5 { + app.update(); + } + } + + fn my_system(_: Res) { + // access state during app update + } + + // Should not panic due to missing resource + App::new() + .set_runner(my_runner) + .add_systems(PreUpdate, my_system) + .run(); + } }