Skip to content

Panic after despawning camera #4227

@geckoxx

Description

@geckoxx

bevy version: main 026563c

When spawning a camera and despawning it later it panics with

thread 'main' panicked at 'view entity should exist: QueryDoesNotMatch', [...]\crates\bevy_core_pipeline\src\main_pass_2d.rs:45:14
use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .add_system(remove_camera)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn_bundle(OrthographicCameraBundle::new_2d());
}

fn remove_camera(
    mut commands: Commands,
    query: Query<Entity, With<Camera>>,
    keyboard_input: Res<Input<KeyCode>>,
) {
    if keyboard_input.just_pressed(KeyCode::Space) {
        for entity in query.iter() {
            commands.entity(entity).despawn();
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behaviorP-CrashA sudden unexpected crash

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions