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

Pressing F on any entity panics #99

Open
franklinblanco opened this issue Mar 24, 2024 · 5 comments
Open

Pressing F on any entity panics #99

franklinblanco opened this issue Mar 24, 2024 · 5 comments

Comments

@franklinblanco
Copy link

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
Copy link
Author

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
Copy link
Owner

2024-03-28.13-50-18.mp4

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
Copy link

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
Copy link

VergilUa commented May 18, 2024

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
Copy link

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.

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