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

ui_focus_system crashes if UI Node is removed by clicking on it. #11572

Closed
Hexorg opened this issue Jan 28, 2024 · 1 comment · Fixed by #11575
Closed

ui_focus_system crashes if UI Node is removed by clicking on it. #11572

Hexorg opened this issue Jan 28, 2024 · 1 comment · Fixed by #11575
Labels
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

@Hexorg
Copy link
Contributor

Hexorg commented Jan 28, 2024

Bevy version

bevy_ui-0.12.1

What you did

I have a UI interaction where a UI node gets deleted when it gets clicked on (Interaction::Pressed).

What went wrong

Panic at bevy_ui-0.12.1/src/stack.rs:63:14:
called Result::unwrap() on an Err value: NoSuchEntity(2v0)

Additional information

Minimal reproducible code below (crashes when you click on "click me"). If you only have one node crash doesn't happen.

use bevy::{prelude::*, ui::ui_focus_system};

fn on_interaction(query:Query<(Entity, &Interaction), Changed<Interaction>>, mut commands:Commands) {
    for (entity, interaction) in &query {
        if *interaction == Interaction::Pressed {
            commands.entity(entity).despawn();
        }
    }
}

fn setup(mut commands:Commands) {
    commands.spawn(NodeBundle::default()).with_children(|parent| {
        parent.spawn((Interaction::None, TextBundle::from_section("click me", TextStyle::default())));
    });
    commands.spawn(Camera3dBundle::default());
}

fn main() {
    let mut app = App::new();
    app.add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .add_systems(Update, (ui_focus_system, on_interaction));
    app.run();
@Hexorg Hexorg added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jan 28, 2024
@alice-i-cecile alice-i-cecile added D-Trivial Nice and easy! A great choice to get started with Bevy P-Crash A sudden unexpected crash A-UI Graphical user interfaces, styles, layouts, and widgets and removed S-Needs-Triage This issue needs to be labelled labels Jan 28, 2024
@alice-i-cecile
Copy link
Member

This is the offending line:

We shouldn't unwrap here: instead, we should just continue. Looks like an easy fix.

github-merge-queue bot pushed a commit that referenced this issue Jan 29, 2024
# Objective

- Fixes #11572

## Solution

- Avoid unconditionally unwrapping the `Result` in the `ui_stack_system`
function.
tjamaan pushed a commit to tjamaan/bevy that referenced this issue Feb 6, 2024
…gine#11575)

# Objective

- Fixes bevyengine#11572

## Solution

- Avoid unconditionally unwrapping the `Result` in the `ui_stack_system`
function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

2 participants