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

Panic with UI hierarchy when no camera is present #12184

Closed
rparrett opened this issue Feb 28, 2024 · 1 comment · Fixed by #12816
Closed

Panic with UI hierarchy when no camera is present #12184

rparrett opened this issue Feb 28, 2024 · 1 comment · Fixed by #12816
Labels
A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior D-Trivial Nice and easy! A great choice to get started with Bevy P-Crash A sudden unexpected crash

Comments

@rparrett
Copy link
Contributor

rparrett commented Feb 28, 2024

Bevy version

main, 0.13

bisected to #10559

Relevant system information

AdapterInfo { name: "Apple M1 Max", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }
SystemInfo { os: "MacOS 14.2.1 ", kernel: "23.2.0", cpu: "Apple M1 Max", core_count: "10", memory: "64.0 GiB" }

What you did

I noticed this while writing some doc examples which were accidentally not no_run.

This is the most minimal repro I can make, but I also see this panic in e.g. the button example modified with no camera.

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands) {
    commands
        .spawn(NodeBundle::default())
        .with_children(|parent| {
            parent.spawn(NodeBundle::default());
        });
}

What went wrong

Received a warning about a camera not being present, which I suppose makes sense.

Received a warning about an "unstyled child in a UI entity hierarchy" which does not make sense as far as I can tell.

Finally, panicked on an unwrap which doesn't seem desirable.

2024-02-28T15:05:02.776557Z  WARN bevy_ui::layout: No camera found to render UI to. To fix this, add at least one camera to the scene.
2024-02-28T15:05:02.776596Z  WARN bevy_ui::layout: Unstyled child in a UI entity hierarchy. You are using an entity without UI components as a child of an entity with UI components, results may be unexpected.
thread 'Compute Task Pool (0)' panicked at crates/bevy_ui/src/layout/mod.rs:131:60:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_ui::layout::ui_layout_system`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!
thread 'main' panicked at /Users/me/.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 { .. }
@rparrett rparrett added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Feb 28, 2024
@rparrett rparrett changed the title Panic with simple UI hierarchy when no camera is present Panic with UI hierarchy when no camera is present Feb 28, 2024
@alice-i-cecile alice-i-cecile added P-Crash A sudden unexpected crash A-UI Graphical user interfaces, styles, layouts, and widgets D-Trivial Nice and easy! A great choice to get started with Bevy A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Feb 28, 2024
@ekropotin
Copy link
Contributor

I want to work on this issue, if it's OK

salvadorcarvalhinho added a commit to salvadorcarvalhinho/bevy that referenced this issue Mar 30, 2024
Created default values to be used in upsert_node, added flag to control warnings about no camera present and created unit test no_camera_ui.
github-merge-queue bot pushed a commit that referenced this issue Apr 22, 2024
# Objective
Add support so bevy_ui can correctly handle an UI hierarchy without a
camera present.

- Fixes #12184

## Solution

As there was no default behavior for what should happen when a camera is
not present in a UI hierarchy, the solution
was based in defining that default behavior and improving the overall
handling of this "exception".


## Changelog

- Create default values to be used in upsert_node
- Add flag to control warnings about no camera present
- Create unit test no_camera_ui (to test if ui handles no camera
present)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior D-Trivial Nice and easy! A great choice to get started with Bevy P-Crash A sudden unexpected crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants