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

Gizmos drawing despawned entities #13383

Closed
iiYese opened this issue May 15, 2024 · 9 comments · Fixed by #13378
Closed

Gizmos drawing despawned entities #13383

iiYese opened this issue May 15, 2024 · 9 comments · Fixed by #13378
Labels
A-Gizmos Visual editor and debug gizmos A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Regression Functionality that used to work but no longer does. Add a test for this! S-Needs-Investigation This issue requires detective work to figure out what's going wrong
Milestone

Comments

@iiYese
Copy link
Contributor

iiYese commented May 15, 2024

Bevy version

f91fd32

Relevant system information

Rust version: 1.78.0
System info:

2024-05-15T18:44:46.562458Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux 39 Nobara Linux", kernel: "6.8.7-201.fsync.fc39.x86_64", cpu: "AMD Ryzen 7 7840HS w/ Radeon 780M Graphics", core_count: "8", memory: "30.6 GiB" }

Adapter info:

AdapterInfo { name: "AMD Radeon RX 6650M (RADV NAVI23)", vendor: 4098, device: 29679, device_type: DiscreteGpu, driver: "radv", driver_info: "Mesa 24.2.0-devel", backend: Vulkan }

What you did

Setup a point to be deleted when the mouse button is pressed anywhere, draw the point with a circle gizmo.

What went wrong

  • Expecting gizmo to no longer draw despawned entity
  • Despawned entity is still drawn
use bevy::prelude::*;

#[derive(Component)]
struct Point(Vec2);

fn setup(mut cmds: Commands) {
    cmds.spawn(Camera2dBundle::default());
    cmds.spawn(Point(Vec2::new(0.0, 150.0)));
}

fn draw(mut gizmos: Gizmos, tree: Query<&Point>) {
    for Point(pos) in tree.iter() {
        gizmos.circle_2d(*pos, 40., Color::WHITE);
    }
}

fn despawn(
    mut cmds: Commands,
    points: Query<Entity, With<Point>>,
    mouse_buttons: Res<ButtonInput<MouseButton>>,
) {
    if mouse_buttons.just_pressed(MouseButton::Left) {
        for entity in points.iter() {
            println!("despawned");
            cmds.entity(entity).despawn();
        }
    }
}

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .add_systems(Update, (draw, despawn).chain())
        .run();
}
@iiYese iiYese added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen A-Gizmos Visual editor and debug gizmos labels May 15, 2024
@alice-i-cecile alice-i-cecile added the S-Needs-Investigation This issue requires detective work to figure out what's going wrong label May 15, 2024
@alice-i-cecile
Copy link
Member

Does this occur on 0.13?

@alice-i-cecile alice-i-cecile added the C-Regression Functionality that used to work but no longer does. Add a test for this! label May 15, 2024
@alice-i-cecile
Copy link
Member

This was likely introduced in #10973 by @Aceeri: I would appreciate a before/after test.

@alice-i-cecile alice-i-cecile added this to the 0.14 milestone May 15, 2024
@iiYese
Copy link
Contributor Author

iiYese commented May 15, 2024

Does this occur on 0.13?

Nope.

@iiYese
Copy link
Contributor Author

iiYese commented May 15, 2024

Video of behavior on f91fd32 Screencast_20240515_195205.webm

@iiYese
Copy link
Contributor Author

iiYese commented May 15, 2024

Additional behavior of bug: After despawning the entity, resizing or fullscreening the window causes whatever state is invalid to be updated making the gizmo no longer be drawn.

Video: Screencast_20240515_195748.webm

@IceSentry
Copy link
Contributor

I just tested it with the #10973 commit and it works correctly. So it's something else. I'll run a git bisect

@iiYese
Copy link
Contributor Author

iiYese commented May 15, 2024

Modifying the code to this:

use bevy::prelude::*;

#[derive(Component)]
struct Point(Vec2);

fn setup(mut cmds: Commands) {
    cmds.spawn(Camera2dBundle::default());
    cmds.spawn(Point(Vec2::new(0.0, 150.0)));
    cmds.spawn(Point(Vec2::new(100.0, 150.0)));
    cmds.spawn(Point(Vec2::new(200.0, 150.0)));
    cmds.spawn(Point(Vec2::new(300.0, 150.0)));
}

fn draw(mut gizmos: Gizmos, tree: Query<&Point>) {
    for Point(pos) in tree.iter() {
        gizmos.circle_2d(*pos, 40., Color::WHITE);
    }
}

fn despawn(
    mut cmds: Commands,
    points: Query<Entity, With<Point>>,
    mouse_buttons: Res<ButtonInput<MouseButton>>,
) {
    if mouse_buttons.just_pressed(MouseButton::Left) {
        for entity in points.iter().take(1) {
            cmds.entity(entity).despawn();
            println!("despawned");
        }
    }
}

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

Reveals that this happens when you go from exactly 1 gizmo being drawn -> 0 gizmos being drawn.
Edit: Wasn't quite correct. Removing the .take(1) shows that it's actually when you go from any N gizmos being drawn -> exactly 0 gizmos being drawn where 0 < N.

Video: Screencast_20240515_203309.webm

@IceSentry
Copy link
Contributor

I'm currently running a bisect to figure out which commit introduced this bug

@IceSentry
Copy link
Contributor

Seems like #12982 is causing the issue. I'm investigating, I'm really not sure how that PR could affect gizmos

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

- Fixes #13377
- Fixes #13383

## Solution

- Even if the number of renderables is empty, the transparent phase need
to run to set the clear color.

## Testing

- Tested on the `clear_color` example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Gizmos Visual editor and debug gizmos A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Regression Functionality that used to work but no longer does. Add a test for this! S-Needs-Investigation This issue requires detective work to figure out what's going wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants