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] - #4231: panic when App::run() is called from Plugin::build() #4241

Closed
wants to merge 5 commits into from

Conversation

Vrixyz
Copy link
Member

@Vrixyz Vrixyz commented Mar 17, 2022

Objective

Fixes #4231.

Solution

This PR implements the solution suggested by @bjorn3 : Use an internal property within App to detect App::run() calls from Plugin::build().


Changelog

  • panic when App::run() is called from Plugin::build()

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Mar 17, 2022
@Vrixyz Vrixyz force-pushed the 4231-plugin-build-warn-app-run branch from cbb3fcc to a35b026 Compare March 17, 2022 15:35
crates/bevy_app/src/app.rs Outdated Show resolved Hide resolved
crates/bevy_app/src/app.rs Outdated Show resolved Hide resolved
@mockersf
Copy link
Member

If this is wanted, it should be done for add_plugins too.

Buuuut... I don't think this is wanted. Why would we block a plugin from calling run? Should a RunPlugin that finish setting up my app then run it be impossible?

@MrGVSV
Copy link
Member

MrGVSV commented Mar 18, 2022

Should a RunPlugin that finish setting up my app then run it be impossible?

Maybe not but in my opinion it's probably something we want users to do. It hides the run call (especially if the plugin has nested plugins). And it might lead to confusion if a user does it (or a crate or a team member) without fully understanding what they're doing.

I just find it to be a potential footgun. But that's just how I feel about it haha

@ghost ghost added A-App Bevy apps and plugins C-Startup A crash that occurs when first attempting to run a Bevy app and removed S-Needs-Triage This issue needs to be labelled labels Mar 18, 2022
@Vrixyz
Copy link
Member Author

Vrixyz commented Mar 18, 2022

While I agree that panic is extreme, I believe allowing Plugins::build() to alter with app execution dramatically such as calling run() is something we want to at least discourage, or even forbid completely.

#1255 refers to order independence for plugins, which comfort this stance.

That said, I'm ok with displaying that as a warning if it's judged too extreme.

Also, if we have real use cases to call App::run() from Plugin::build(), we might want to provide a way to silence that warning.

@bjorn3
Copy link
Contributor

bjorn3 commented Mar 18, 2022

Plugins should use .set_runner() instead of running the app themself IMO. Having an a plugin run the app immediately would result in any calls after the current .add_plugin to be ignored.

Vrixyz added a commit to Vrixyz/bevy that referenced this pull request Mar 18, 2022
@alice-i-cecile
Copy link
Member

alice-i-cecile commented May 16, 2022

Plugins should use .set_runner() instead of running the app themself IMO. Having an a plugin run the app immediately would result in any calls after the current .add_plugin to be ignored.

I agree quite strongly with @bjorn3 here.

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit, then this LGTM.

crates/bevy_app/src/app.rs Outdated Show resolved Hide resolved
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label May 16, 2022
@mockersf
Copy link
Member

mockersf commented May 16, 2022

I still really don't like this change, but if this gets to be merged could you add a panic section to the doc comment of the run method?

@alice-i-cecile alice-i-cecile removed the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label May 17, 2022
@alice-i-cecile
Copy link
Member

Agreed; I'm going to block on that suggestion.

Vrixyz added a commit to Vrixyz/bevy that referenced this pull request May 18, 2022
@Vrixyz Vrixyz force-pushed the 4231-plugin-build-warn-app-run branch 2 times, most recently from 38435ae to 971bdbe Compare May 18, 2022 07:44
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Controversial There is active debate or serious implications around merging this PR labels May 18, 2022
Copy link
Member

@cart cart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not in love with this pattern, but I see it largely as an indicator that we should consider a more structured / limited plugin api.

I'm ok with adopting this in the interest of preventing a pattern that we will likely disallow (statically / structurally) in the future.

If conflicts are resolved I'm down to merge this.

@alice-i-cecile alice-i-cecile added S-Adopt-Me The original PR author has no intent to complete this work. Pick me up! and removed X-Controversial There is active debate or serious implications around merging this PR labels Dec 21, 2022
@alice-i-cecile
Copy link
Member

@Vrixyz feel free to rebase yourself and I'll remove the Adopt-Me label :) But we took ages on this so I want to make sure you don't feel obliged to.

Vrixyz added a commit to Vrixyz/bevy that referenced this pull request Dec 21, 2022
@Vrixyz Vrixyz force-pushed the 4231-plugin-build-warn-app-run branch from 971bdbe to fe8abaa Compare December 21, 2022 13:38
@Vrixyz Vrixyz force-pushed the 4231-plugin-build-warn-app-run branch from fe8abaa to aa4d904 Compare December 21, 2022 14:02
@alice-i-cecile alice-i-cecile removed the S-Adopt-Me The original PR author has no intent to complete this work. Pick me up! label Dec 22, 2022
@Vrixyz
Copy link
Member Author

Vrixyz commented Dec 22, 2022

The rebase was not so straightforward, I ended up in setting is_building_plugin within App::add_boxed_plugin which is called by App::add_plugin and PluginGroupBuilder::finish.

I have a small doubt about dynamically loaded plugins which would not trigger the warning panic, but as it's a more advanced feature I guess it's fine.

@alice-i-cecile
Copy link
Member

Yep I'm totally fine with this not working for dynamic plugins.

@alice-i-cecile
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Dec 24, 2022
# Objective

Fixes #4231.

## Solution

This PR implements the solution suggested by @bjorn3 : Use an internal property within `App` to detect `App::run()` calls from `Plugin::build()`.

---

## Changelog

- panic when App::run() is called from Plugin::build()
@bors bors bot changed the title #4231: panic when App::run() is called from Plugin::build() [Merged by Bors] - #4231: panic when App::run() is called from Plugin::build() Dec 25, 2022
@bors bors bot closed this Dec 25, 2022
alradish pushed a commit to alradish/bevy that referenced this pull request Jan 22, 2023
…bevyengine#4241)

# Objective

Fixes bevyengine#4231.

## Solution

This PR implements the solution suggested by @bjorn3 : Use an internal property within `App` to detect `App::run()` calls from `Plugin::build()`.

---

## Changelog

- panic when App::run() is called from Plugin::build()
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
…bevyengine#4241)

# Objective

Fixes bevyengine#4231.

## Solution

This PR implements the solution suggested by @bjorn3 : Use an internal property within `App` to detect `App::run()` calls from `Plugin::build()`.

---

## Changelog

- panic when App::run() is called from Plugin::build()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-App Bevy apps and plugins C-Startup A crash that occurs when first attempting to run a Bevy app S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Restrict available methods on App from Plugin::Build()
8 participants