jakobhellermann / bevy_editor_pls

In-App editor tools for bevy applications
Other
727 stars 74 forks source link

Pressing F on any entity panics #99

Open franklinblanco opened 5 months ago

franklinblanco commented 5 months ago
thread 'Compute Task Pool (3)' panicked at /Users/REDACTED/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_editor_pls_default_windows-0.8.0/src/cameras/mod.rs:437:64:
called `Result::unwrap()` on an `Err` value: NoEntities("bevy_ecs::query::state::QueryState<(&mut bevy_transform::components::transform::Transform, core::option::Option<&mut bevy_editor_pls_default_windows::cameras::camera_3d_panorbit::PanOrbitCamera>, core::option::Option<&mut bevy_render::camera::projection::OrthographicProjection>), bevy_ecs::query::filter::With<bevy_editor_pls_default_windows::cameras::ActiveEditorCamera>>")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_editor_pls_default_windows::cameras::focus_selected`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!
thread 'main' panicked at /Users/REDACTED/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.11/src/platform_impl/macos/app_state.rs:387:33:
called `Result::unwrap()` on an `Err` value: PoisonError { .. }
franklinblanco commented 5 months ago

I just clicked an entity in the editor and pressed F. That is the error. Cargo.toml

bevy = { version = "0.13.1" }
bevy_editor_pls = "0.8"
jakobhellermann commented 5 months ago

https://github.com/jakobhellermann/bevy_editor_pls/assets/22177966/6ea188b2-bd12-49bf-ba1a-e7767af33f8b

Hm, I can't reproduce, for me it works fine. From the panic it looks like there is no ActiveEditorCamera but I don't know how that can happen :/

VergilUa commented 3 months ago

Older versions have this issue as well, e.g. bevy = { version = "0.12.1", features = ["bevy_winit"] } bevy_editor_pls = "0.7.0"

I've got a multiwindow setup like so:

fn setup_editor_window() -> EditorPlugin {
    EditorPlugin::
    in_new_window(Default::default(), Window {
        title: EDITOR_WINDOW_NAME.to_string(),
        mode: WindowMode::Windowed,
        position: WindowPosition::Centered(MonitorSelection::Index(1)),
        ..Default::default()
    })
}

WTR:

  1. Start an application and editor on second monitor;
  2. Select entity on the second monitor within Hierarchy window
  3. Press F

If I manually select different camera mode, and then switch back - it does not panic.

VergilUa commented 3 months ago

Ended up forking repo and modifying cameras.mod @ 444 like so:

        let Ok((mut camera_tf, pan_orbit_cam, ortho)) = active_cam.get_single_mut() else {
            let camera_count = active_cam.iter().count();

            info!("Cannot focus. Select camera first. Total active cameras: {:?}", camera_count);
            return;
        };

Active camera count is indeed zero for some reason. Editor should not panic / shutdown whole editor + application for this case anyway. Notifying user should be enough.

VergilUa commented 3 months ago

As an alternative fix - perhaps introduce some kind of active camera settings into the plugin? So that specific active camera could be applied during application initialization. Exposing somehow access to the active camera state from code would be nice.

Ended up with this solution:

impl CameraWindowState {
    /// Sets current active editor camera to the specified `EditorCamKind`
    pub fn set_active_camera(&mut self, camera: EditorCamKind, world: &mut World)
    {
                // This should be identitical to viewport_toolbar_ui internal logic (on button click)
        if self.editor_cam != camera {
            set_active_editor_camera_marker(world, camera);
        }

        self.editor_cam = camera;
    }
}

Then in a separate system after initialization:

pub fn switch_to_2d_camera(
    world: &mut World,
) {
    ...

    world.resource_scope(|world, mut editor: Mut<Editor>| {
        let Some(camera_window_state) = editor.window_state_mut::<CameraWindow>() else {
            return;
        };

        camera_window_state.set_active_camera(EditorCamKind::D2PanZoom, world);
        info!("Switched to 2d camera");
    });

    ...
}

This works and switches camera to the proper state on application start. Though requires a separate system to do so.