Skip to content

can only add a plugin once#3988

Closed
mockersf wants to merge 3 commits intobevyengine:mainfrom
mockersf:plugin-control
Closed

can only add a plugin once#3988
mockersf wants to merge 3 commits intobevyengine:mainfrom
mockersf:plugin-control

Conversation

@mockersf
Copy link
Member

  • a plugin group can only be added once
  • unless specified by the plugin author, a plugin can only be added once
  • add a method on app to check if a plugin has been added

split from #2988

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Feb 19, 2022
@alice-i-cecile alice-i-cecile added A-App Bevy apps and plugins C-Usability A targeted quality-of-life change that makes Bevy easier to use and removed S-Needs-Triage This issue needs to be labelled labels Feb 19, 2022
@james7132 james7132 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 Feb 19, 2022
) {
if let Some(existing_from_group) = self.plugins.insert(*plugin_type, from_group) {
match (from_group, existing_from_group) {
(None, None) => panic!("Plugin \"{}\" was already added", plugin_name),
Copy link
Member

Choose a reason for hiding this comment

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

Before we add panics here, I think we should discuss moving in the direction of "plugins add the plugins they depend on and bevy only initializes each plugin once". With this, dependencies would need to be implicit. But we could make them explicit if we just de-dupe unique plugins.

However this gets a bit messy if we couple configuration to specific plugin instances, because then we've added the ability to init with multiple conflicting configs.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, a more comprehensive solution with some more involved architectural design of how plugins work would be my preferred solution. You’re small but significant fix of collecting all the plugins and deduping then initializing is good and easier fix. At some point bevy will need a more sophisticated plugin architecture, do you have an idea when you would want to work on that (or just let alice do it in her existing rfc for this more complex but more robust plugin architecture after stageless is rolled out?

@alice-i-cecile alice-i-cecile added the X-Needs-SME This type of work requires an SME to approve it. label Apr 22, 2022
mockersf and others added 3 commits April 26, 2022 01:48
T: PluginGroup,
F: FnOnce(&mut PluginGroupBuilder) -> &mut PluginGroupBuilder,
{
if self.plugins.insert(TypeId::of::<T>(), None).is_some() {
Copy link
Member

Choose a reason for hiding this comment

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

Is the unique constraint on groups needed? If it contains a unique plugin, it will already fail
There might be libraries adding groups of not unique plugins.

}

/// Check that a plugin has already been added to the app.
pub fn is_plugin_added<T>(&self) -> bool
Copy link
Member

Choose a reason for hiding this comment

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

I find the naming a bit confusing here. Not every plugin is added to the hashmap. At the moment it also contains plugin groups.

Maybe is_unique_plugin_added would fit better?

@alice-i-cecile
Copy link
Member

Closing in favor of #6411; we can reopen if others feel strongly that this complexity is warranted.

bors bot pushed a commit that referenced this pull request Oct 31, 2022
# Objective

- Make it impossible to add a plugin twice
- This is going to be more a risk for plugins with configurations, to avoid things like `App::new().add_plugins(DefaultPlugins).add_plugin(ImagePlugin::default_nearest())`

## Solution

- Panic when a plugin is added twice
- It's still possible to mark a plugin as not unique by overriding `is_unique`
- ~~Simpler version of~~ #3988 (not simpler anymore because of how `PluginGroupBuilder` implements `PluginGroup`)
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

- Make it impossible to add a plugin twice
- This is going to be more a risk for plugins with configurations, to avoid things like `App::new().add_plugins(DefaultPlugins).add_plugin(ImagePlugin::default_nearest())`

## Solution

- Panic when a plugin is added twice
- It's still possible to mark a plugin as not unique by overriding `is_unique`
- ~~Simpler version of~~ bevyengine#3988 (not simpler anymore because of how `PluginGroupBuilder` implements `PluginGroup`)
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-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Needs-SME This type of work requires an SME to approve it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants