jakobhellermann / bevy_editor_pls

In-App editor tools for bevy applications
Other
758 stars 78 forks source link

Infinite Viewport Size #97

Closed dylanowen closed 7 months ago

dylanowen commented 8 months ago

I've been hitting this error intermittently:

WARN bevy_editor_pls_default_windows::cameras: editor viewport size is infinite

From set_main_pass_viewport which results in bevy's ui crashing:

attempt to add with overflow
stack backtrace:
thread 'Compute Task Pool (4)' panicked at /Users/dylan.owen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/glam-0.25.0/src/u32/uvec2.rs:521:23:
attempt to add with overflow
   0: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
   2: core::panicking::panic
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:144:5
   3: <u32 as core::ops::arith::Add>::add
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/arith.rs:103:45
   4: <glam::u32::uvec2::UVec2 as core::ops::arith::Add>::add
             at /Users/dylan.owen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/glam-0.25.0/src/u32/uvec2.rs:521:16
   5: bevy_render::camera::camera::Camera::physical_viewport_rect
             at /Users/dylan.owen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_render-0.13.0/src/camera/camera.rs:254:19
   6: bevy_ui::render::extract_default_ui_camera_view
             at /Users/dylan.owen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ui-0.13.0/src/render/mod.rs:512:13

We set the viewport initially to Infinity and then update it under: bevy_editor_pls_core-0.8.0/src/editor.rs:529 which seems like it should be called before set_main_pass_viewport:

.add_systems(
    Update,
    Editor::system
        .in_set(EditorSet::UI)
app.add_systems(
    PostUpdate,
    set_main_pass_viewport
        .after(bevy_editor_pls_core::EditorSet::UI)

However we actually activate our camera as part of:

 .add_systems(
    Update,
    set_editor_cam_active
        .before(camera_3d_panorbit::CameraSystem::EditorCam3dPanOrbit)
        .before(camera_3d_free::CameraSystem::EditorCam3dFree)
        .before(camera_2d_panzoom::CameraSystem::EditorCam2dPanZoom),
)

Which has no ordering in relation to Editor::system that I am aware of. Even with an ordering of set_editor_cam_active and Editor::system that still wouldn't be enough. editor_controls_system activates the Editor initially which kicks this whole thing off and it's possible for Editor::system to run, then editor_controls_system then set_editor_cam_active.

.add_systems(Update, controls::editor_controls_system);

What I think we would really need would be something like

Editor::system.after(editor_controls_system)

set_editor_cam_active.after(bevy_editor_pls_core::EditorSet::UI)

but these systems aren't even in the same crates. Maybe the easiest option is to set our viewport to 640x480 initially, we'll get a flicker in scenarios like this but nothing will crash. Also we'll still get a warning if the viewport is changed to be infinity (and probably a crash).

dylanowen commented 8 months ago

I opened https://github.com/jakobhellermann/bevy_editor_pls/pull/98 to address this

jakobhellermann commented 7 months ago

fixed with #98