Skip to content

Commit

Permalink
bevyengine#4241: fix PR feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz committed Mar 18, 2022
1 parent a35b026 commit 00ebeec
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub struct App {
sub_apps: HashMap<Box<dyn AppLabel>, SubApp>,
/// A private marker to prevent incorrect calls to `App::run()` from `Plugin::build()`
/// <https://github.com/bevyengine/bevy/issues/4231>
is_from_plugin_build: bool,
is_building_plugin: bool,
}

/// Each [`SubApp`] has its own [`Schedule`] and [`World`], enabling a separation of concerns.
Expand Down Expand Up @@ -102,7 +102,7 @@ impl App {
schedule: Default::default(),
runner: Box::new(run_once),
sub_apps: HashMap::default(),
is_from_plugin_build: false,
is_building_plugin: false,
}
}

Expand Down Expand Up @@ -133,8 +133,8 @@ impl App {
let _bevy_app_run_guard = bevy_app_run_span.enter();

let mut app = std::mem::replace(self, App::empty());
if app.is_from_plugin_build {
panic!("App::Run() is called from a Plugin::Build(), which might result in other initialization code not run.");
if app.is_building_plugin {
panic!("App::run() was called from within Plugin::Build(), which is not allowed.");
}
let runner = std::mem::replace(&mut app.runner, Box::new(run_once));
(runner)(app);
Expand Down Expand Up @@ -769,9 +769,9 @@ impl App {
T: Plugin,
{
debug!("added plugin: {}", plugin.name());
self.is_from_plugin_build = true;
self.is_building_plugin = true;
plugin.build(self);
self.is_from_plugin_build = false;
self.is_building_plugin = false;
self
}

Expand All @@ -797,8 +797,10 @@ impl App {
/// ```
pub fn add_plugins<T: PluginGroup>(&mut self, mut group: T) -> &mut Self {
let mut plugin_group_builder = PluginGroupBuilder::default();
self.is_building_plugin = true;
group.build(&mut plugin_group_builder);
plugin_group_builder.finish(self);
self.is_building_plugin = false;
self
}

Expand Down

0 comments on commit 00ebeec

Please sign in to comment.