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

A component with a nested Inspectable field causes a panic when expanded #25

Open
tgecho opened this issue Jul 13, 2022 · 1 comment
Open

Comments

@tgecho
Copy link

tgecho commented Jul 13, 2022

#[derive(Component, Inspectable, Debug)]
pub struct Behavior {
    actor: Entity,
    state: BehaviorState,
}

#[derive(Inspectable, PartialEq, Eq, Debug)]
pub enum BehaviorState {
    Inactive,
    Running,
    Succeeded,
    Failed,
}

When I try to expand the Behavior component in the inspector pane, it crashes with

thread 'main' panicked at 'assertion failed: !self.contains_resource::<R>()', ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_ecs/src/world/mod.rs:1072:9
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: bevy_ecs::world::World::resource_scope
             at ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_ecs/src/world/mod.rs:1072:9
   4: bevy_editor_pls_default_windows::inspector::inspector
             at ~/.cargo/git/checkouts/bevy_editor_pls-aa84c1e9122cf1d6/73e7e3c/crates/bevy_editor_pls_default_windows/src/inspector.rs:34:5
   5: <bevy_editor_pls_default_windows::inspector::InspectorWindow as bevy_editor_pls_core::editor_window::EditorWindow>::ui
             at ~/.cargo/git/checkouts/bevy_editor_pls-aa84c1e9122cf1d6/73e7e3c/crates/bevy_editor_pls_default_windows/src/inspector.rs:19:9
   6: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/06754d8852bea286a3a76d373ccd17e66afb5a8b/library/alloc/src/boxed.rs:1948:9
   7: bevy_editor_pls_core::editor::Editor::editor_window_inner
             at ~/.cargo/git/checkouts/bevy_editor_pls-aa84c1e9122cf1d6/73e7e3c/crates/bevy_editor_pls_core/src/editor.rs:488:9
   8: bevy_editor_pls_core::editor::Editor::editor_window::{{closure}}
             at ~/.cargo/git/checkouts/bevy_editor_pls-aa84c1e9122cf1d6/73e7e3c/crates/bevy_editor_pls_core/src/editor.rs:458:17
   9: bevy_editor_pls_core::drag_and_drop::drop_target
             at ~/.cargo/git/checkouts/bevy_editor_pls-aa84c1e9122cf1d6/73e7e3c/crates/bevy_editor_pls_core/src/drag_and_drop.rs:53:15
  10: bevy_editor_pls_core::editor::Editor::editor_window
             at ~/.cargo/git/checkouts/bevy_editor_pls-aa84c1e9122cf1d6/73e7e3c/crates/bevy_editor_pls_core/src/editor.rs:456:29
  11: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/06754d8852bea286a3a76d373ccd17e66afb5a8b/library/alloc/src/boxed.rs:1934:9
  12: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/06754d8852bea286a3a76d373ccd17e66afb5a8b/library/alloc/src/boxed.rs:1934:9
  13: egui::containers::frame::Frame::show_dyn
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/egui-0.17.0/src/containers/frame.rs:170:19
  14: egui::containers::frame::Frame::show
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/egui-0.17.0/src/containers/frame.rs:161:9
  15: egui::containers::panel::SidePanel::show_inside_dyn
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/egui-0.17.0/src/containers/panel.rs:243:30
  16: egui::containers::panel::SidePanel::show_dyn
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/egui-0.17.0/src/containers/panel.rs:307:30
  17: egui::containers::panel::SidePanel::show
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/egui-0.17.0/src/containers/panel.rs:292:9
  18: bevy_editor_pls_core::editor::Editor::editor_ui
             at ~/.cargo/git/checkouts/bevy_editor_pls-aa84c1e9122cf1d6/73e7e3c/crates/bevy_editor_pls_core/src/editor.rs:302:19
  19: bevy_editor_pls_core::editor::Editor::system::{{closure}}::{{closure}}::{{closure}}::{{closure}}
             at ~/.cargo/git/checkouts/bevy_editor_pls-aa84c1e9122cf1d6/73e7e3c/crates/bevy_editor_pls_core/src/editor.rs:265:33
  20: bevy_ecs::world::World::resource_scope
             at ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_ecs/src/world/mod.rs:1071:22
  21: bevy_editor_pls_core::editor::Editor::system::{{closure}}::{{closure}}::{{closure}}
             at ~/.cargo/git/checkouts/bevy_editor_pls-aa84c1e9122cf1d6/73e7e3c/crates/bevy_editor_pls_core/src/editor.rs:263:25
  22: bevy_ecs::world::World::resource_scope
             at ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_ecs/src/world/mod.rs:1071:22
  23: bevy_editor_pls_core::editor::Editor::system::{{closure}}::{{closure}}
             at ~/.cargo/git/checkouts/bevy_editor_pls-aa84c1e9122cf1d6/73e7e3c/crates/bevy_editor_pls_core/src/editor.rs:261:17
  24: bevy_ecs::world::World::resource_scope
             at ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_ecs/src/world/mod.rs:1071:22
  25: bevy_editor_pls_core::editor::Editor::system::{{closure}}
             at ~/.cargo/git/checkouts/bevy_editor_pls-aa84c1e9122cf1d6/73e7e3c/crates/bevy_editor_pls_core/src/editor.rs:260:13
  26: bevy_ecs::world::World::resource_scope
             at ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_ecs/src/world/mod.rs:1071:22
  27: bevy_editor_pls_core::editor::Editor::system
             at ~/.cargo/git/checkouts/bevy_editor_pls-aa84c1e9122cf1d6/73e7e3c/crates/bevy_editor_pls_core/src/editor.rs:259:9
  28: core::ops::function::FnMut::call_mut
             at /rustc/06754d8852bea286a3a76d373ccd17e66afb5a8b/library/core/src/ops/function.rs:164:5
  29: <bevy_ecs::system::exclusive_system::ExclusiveSystemFn<F> as bevy_ecs::system::exclusive_system::ExclusiveSystem>::run
             at ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_ecs/src/system/exclusive_system.rs:37:9
  30: <bevy_ecs::schedule::stage::SystemStage as bevy_ecs::schedule::stage::Stage>::run
             at ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_ecs/src/schedule/stage.rs:842:25
  31: bevy_ecs::schedule::Schedule::run_once
             at ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_ecs/src/schedule/mod.rs:341:13
  32: bevy_app::app::App::update
             at ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_app/src/app.rs:114:9
  33: bevy_winit::winit_runner_with::{{closure}}
             at ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_winit/src/lib.rs:563:21
  34: <winit::platform_impl::platform::app_state::EventLoopHandler<T> as winit::platform_impl::platform::app_state::EventHandler>::handle_nonuser_event::{{closure}}
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/macos/app_state.rs:101:13
  35: winit::platform_impl::platform::app_state::EventLoopHandler<T>::with_callback
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/macos/app_state.rs:79:13
  36: <winit::platform_impl::platform::app_state::EventLoopHandler<T> as winit::platform_impl::platform::app_state::EventHandler>::handle_nonuser_event
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/macos/app_state.rs:100:9
  37: winit::platform_impl::platform::app_state::Handler::handle_nonuser_event
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/macos/app_state.rs:206:21
  38: winit::platform_impl::platform::app_state::AppState::cleared
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/macos/app_state.rs:387:9
  39: winit::platform_impl::platform::observer::control_flow_end_handler::{{closure}}
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/macos/observer.rs:180:21
  40: winit::platform_impl::platform::observer::control_flow_handler::{{closure}}
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/macos/observer.rs:142:57
  41: std::panicking::try::do_call
             at /rustc/06754d8852bea286a3a76d373ccd17e66afb5a8b/library/std/src/panicking.rs:492:40
  42: std::panicking::try
             at /rustc/06754d8852bea286a3a76d373ccd17e66afb5a8b/library/std/src/panicking.rs:456:19
  43: std::panic::catch_unwind
             at /rustc/06754d8852bea286a3a76d373ccd17e66afb5a8b/library/std/src/panic.rs:137:14
  44: winit::platform_impl::platform::event_loop::stop_app_on_panic
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/macos/event_loop.rs:229:11
  45: winit::platform_impl::platform::observer::control_flow_handler
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/macos/observer.rs:142:5
  46: winit::platform_impl::platform::observer::control_flow_end_handler
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/macos/observer.rs:175:9
  47: <unknown>
  48: <unknown>
  49: <unknown>
  50: <unknown>
  51: <unknown>
  52: <unknown>
  53: <unknown>
  54: <unknown>
  55: <unknown>
  56: <unknown>
  57: <() as objc::message::MessageArguments>::invoke
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:128:17
  58: objc::message::platform::send_unverified
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/message/apple/mod.rs:27:9
  59: objc::message::send_message
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/macos/event_loop.rs:188:22
  60: winit::platform_impl::platform::event_loop::EventLoop<T>::run_return::{{closure}}
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/macros.rs:133:15
  61: objc::rc::autorelease::autoreleasepool
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/rc/autorelease.rs:29:5
  62: winit::platform_impl::platform::event_loop::EventLoop<T>::run_return
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/macos/event_loop.rs:178:9
  63: winit::platform_impl::platform::event_loop::EventLoop<T>::run
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/macos/event_loop.rs:157:9
  64: winit::event_loop::EventLoop<T>::run
             at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/event_loop.rs:154:9
  65: bevy_winit::run
             at ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_winit/src/lib.rs:180:5
  66: bevy_winit::winit_runner_with
             at ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_winit/src/lib.rs:604:9
  67: bevy_winit::winit_runner
             at ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_winit/src/lib.rs:220:5
  68: core::ops::function::Fn::call
             at /rustc/06754d8852bea286a3a76d373ccd17e66afb5a8b/library/core/src/ops/function.rs:77:5
  69: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/06754d8852bea286a3a76d373ccd17e66afb5a8b/library/alloc/src/boxed.rs:1948:9
  70: bevy_editor_pls_default_windows::debug_settings::debugdump::setup::{{closure}}
             at ~/.cargo/git/checkouts/bevy_editor_pls-aa84c1e9122cf1d6/73e7e3c/crates/bevy_editor_pls_default_windows/src/debug_settings/debugdump.rs:50:9
  71: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/06754d8852bea286a3a76d373ccd17e66afb5a8b/library/alloc/src/boxed.rs:1948:9
  72: bevy_app::app::App::run
             at ~/.cargo/git/checkouts/bevy-0ebda94b0d66b172/f38cef0/crates/bevy_app/src/app.rs:130:9
  73: bevy_blocks::main
             at ./src/main.rs:22:5
  74: core::ops::function::FnOnce::call_once
             at /rustc/06754d8852bea286a3a76d373ccd17e66afb5a8b/library/core/src/ops/function.rs:248:5

This works fine if I use the enum as a component directly. It also works as is in bevy-inspector-egui.

@jakobhellermann
Copy link
Owner

jakobhellermann commented Jul 18, 2022

The panic seems to happen when doing something like

world.resource_scope(|res: Mut<Resource>, world| {
  world.insert_resource(Resource::default());
});

but I'm not sure on which resource.

The panic message could really use some detail (bevyengine/bevy#5365).

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

2 participants