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

Adding EguiPlugin from multiple locations wrapped with is_plugin_added is failing causing panic #252

Open
rajsahae opened this issue Jan 23, 2024 · 3 comments

Comments

@rajsahae
Copy link

rajsahae commented Jan 23, 2024

I originally posted this in the Bevy Q&A list but after looking a bit more, I'm wondering if it's an issue with this library?

bevyengine/bevy#11482

For convenience, I have copy/pasted the content of the original post here:


I have a plugin that is using EguiPlugin in my app, and I also have some dependencies that use it (bevy_editor_pls).

It's wrapped in a guard (with some added debug logging not shown in the code but you can see the output in the logs below) so that it should not be added more than once

        if !app.is_plugin_added::<EguiPlugin>() {
            app.add_plugins(EguiPlugin);
        }

However this guard doesn't seem to be working. When I pull in my dependency bevy_editor_pls that I know also includes the plugin with the same kind of guard

https://github.com/jakobhellermann/bevy_editor_pls/blob/main/crates/bevy_editor_pls_core/src/lib.rs#L65

and I run my app, I get a panic with a message indicating it has tried to duplicate the loading of EguiPlugin

2024-01-23T00:55:09.500689Z DEBUG bevy_app::app: added plugin: my_app::MyEditorPlugin
2024-01-23T00:55:09.500693Z DEBUG bevy_app::app: added plugin: bevy_editor_pls::EditorPlugin
2024-01-23T00:55:09.500704Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_core::EditorPlugin
2024-01-23T00:55:09.500719Z DEBUG bevy_app::app: added plugin: bevy_inspector_egui::DefaultInspectorConfigPlugin
2024-01-23T00:55:09.500779Z DEBUG bevy_app::app: added plugin: bevy_egui::EguiPlugin
2024-01-23T00:55:09.500802Z DEBUG bevy_app::app: added plugin: bevy_render::extract_resource::ExtractResourcePlugin<bevy_egui::EguiUserTextures>
2024-01-23T00:55:09.500811Z DEBUG bevy_app::app: added plugin: bevy_render::extract_resource::ExtractResourcePlugin<bevy_egui::render_systems::ExtractedEguiManagedTextures>
2024-01-23T00:55:09.500826Z DEBUG bevy_app::app: added plugin: bevy_render::extract_resource::ExtractResourcePlugin<bevy_egui::EguiSettings>
2024-01-23T00:55:09.500831Z DEBUG bevy_app::app: added plugin: bevy_render::extract_component::ExtractComponentPlugin<bevy_egui::EguiContext>
2024-01-23T00:55:09.500838Z DEBUG bevy_app::app: added plugin: bevy_render::extract_component::ExtractComponentPlugin<bevy_egui::WindowSize>
2024-01-23T00:55:09.500843Z DEBUG bevy_app::app: added plugin: bevy_render::extract_component::ExtractComponentPlugin<bevy_egui::EguiRenderOutput>
2024-01-23T00:55:09.500947Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_core::WindowSetupPlugin<bevy_editor_pls_default_windows::hierarchy::HierarchyWindow>
2024-01-23T00:55:09.500977Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_core::WindowSetupPlugin<bevy_editor_pls_default_windows::assets::AssetsWindow>
2024-01-23T00:55:09.500981Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_core::WindowSetupPlugin<bevy_editor_pls_default_windows::inspector::InspectorWindow>
2024-01-23T00:55:09.500986Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_core::WindowSetupPlugin<bevy_editor_pls_default_windows::debug_settings::DebugSettingsWindow>
2024-01-23T00:55:09.501010Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_core::WindowSetupPlugin<bevy_editor_pls_default_windows::add::AddWindow>
2024-01-23T00:55:09.501015Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_core::WindowSetupPlugin<bevy_editor_pls_default_windows::diagnostics::DiagnosticsWindow>
2024-01-23T00:55:09.501017Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_core::WindowSetupPlugin<bevy_editor_pls_default_windows::renderer::RendererWindow>
2024-01-23T00:55:09.501019Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_core::WindowSetupPlugin<bevy_editor_pls_default_windows::cameras::CameraWindow>
2024-01-23T00:55:09.501027Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_default_windows::cameras::camera_2d_panzoom::PanCamPlugin
2024-01-23T00:55:09.501041Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_default_windows::cameras::camera_3d_free::FlycamPlugin
2024-01-23T00:55:09.501048Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_default_windows::cameras::camera_3d_panorbit::PanOrbitCameraPlugin
2024-01-23T00:55:09.501062Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_core::WindowSetupPlugin<bevy_editor_pls_default_windows::resources::ResourcesWindow>
2024-01-23T00:55:09.501285Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_core::WindowSetupPlugin<bevy_editor_pls_default_windows::scenes::SceneWindow>
2024-01-23T00:55:09.501290Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_core::WindowSetupPlugin<bevy_editor_pls_default_windows::gizmos::GizmoWindow>
2024-01-23T00:55:09.501349Z DEBUG bevy_app::app: added plugin: bevy_editor_pls_core::WindowSetupPlugin<bevy_editor_pls::controls::ControlsWindow>
2024-01-23T00:55:09.501352Z DEBUG bevy_app::app: added plugin: bevy_pbr::wireframe::WireframePlugin
2024-01-23T00:55:09.501422Z DEBUG bevy_app::app: added plugin: bevy_render::extract_resource::ExtractResourcePlugin<bevy_pbr::wireframe::WireframeConfig>
2024-01-23T00:55:09.501430Z DEBUG bevy_app::app: added plugin: bevy_render::extract_component::ExtractComponentPlugin<bevy_pbr::wireframe::Wireframe>
2024-01-23T00:55:09.501478Z DEBUG bevy_app::app: added plugin: my_app::pan_orbit_camera::PanOrbitCameraPlugin
2024-01-23T00:55:09.501526Z DEBUG bevy_app::app: added plugin: my_app::MyPlugin
egui plugins: []
egui added: false
2024-01-23T00:55:09.501614Z DEBUG bevy_app::app: added plugin: bevy_egui::EguiPlugin
thread 'main' panicked at /home/sahae/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_app-0.11.3/src/plugin.rs:96:17:
Error adding plugin bevy_egui::EguiPlugin: : plugin was already added in application
stack backtrace:
   0: rust_begin_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
   2: <P as bevy_app::plugin::sealed::Plugins<bevy_app::plugin::sealed::PluginMarker>>::add_to_app
             at /home/sahae/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_app-0.11.3/src/plugin.rs:96:17
   3: bevy_app::app::App::add_plugins
             at /home/sahae/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_app-0.11.3/src/app.rs:803:9
   4: <my_app::MyPlugin as bevy_app::plugin::Plugin>::build
             at ./crates/my_app/src/lib.rs:205:13
   5: bevy_app::app::App::add_boxed_plugin::{{closure}}
             at /home/sahae/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_app-0.11.3/src/app.rs:713:55
   6: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
   7: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panic/unwind_safe.rs:272:9
   8: std::panicking::try::do_call
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40
   9: std::panicking::try
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19
  10: std::panic::catch_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14
  11: bevy_app::app::App::add_boxed_plugin
             at /home/sahae/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_app-0.11.3/src/app.rs:713:22
  12: <P as bevy_app::plugin::sealed::Plugins<bevy_app::plugin::sealed::PluginMarker>>::add_to_app
             at /home/sahae/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_app-0.11.3/src/plugin.rs:94:17
  13: <(S0,S1,S2,S3,S4,S5,S6,S7,S8) as bevy_app::plugin::sealed::Plugins<(bevy_app::plugin::sealed::PluginsTupleMarker,P0,P1,P2,P3,P4,P5,P6,P7,P8)>>::add_to_app
             at /home/sahae/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_app-0.11.3/src/plugin.rs:118:23
  14: bevy_app::app::App::add_plugins
             at /home/sahae/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_app-0.11.3/src/app.rs:803:9
  15: my_app::main
             at ./src/main.rs:182:5
  16: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5

I have looked at the bevy code for how the plugin is loaded and detected and it retrieves a boxed ref for the plugin and checks a downcast_ref of the trait obj inside the box and in this case that is somehow returning false (I logged it above).

I do see that the add_plugin doesn't add the plugin right away. It adds a placeholder then has the plugin build itself, and then adds it back if that succeeds. I have no idea if that is relevant. But it seems clear that the plugin_name_added HashSet has the plugin name in it, but the plugin_registry doesn't think it has the plugin yet.

As a secondary test, I tried the same thing with a different plugin and that seemed to work, so this may be some issue with bevy_egui / EguiPlugin and how it builds, and not with Bevy itself. But looking at the EguiPlugin build function so far nothing jumps out to me as to why this would be an issue.

That's as far as I've gotten, I hope someone has an idea what is going on?

@Davoodeh
Copy link

Ah wait its bevy_editor_pls using a outdated bevy_egui dependency I believe

Which dependency exactly? I believe I'm facing a similar issue with bevy_panorbit_camera crate (not sure tho, beginner level).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@rajsahae @Davoodeh and others