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

0.12 bug: despawn + spawn during state change, without spawning texture, panics #509

Closed
MeoMix opened this issue Feb 2, 2024 · 0 comments · Fixed by #510
Closed

0.12 bug: despawn + spawn during state change, without spawning texture, panics #509

MeoMix opened this issue Feb 2, 2024 · 0 comments · Fixed by #510

Comments

@MeoMix
Copy link
Contributor

MeoMix commented Feb 2, 2024

Minimal Repro Repo: https://github.com/MeoMix/bevy_bug_example

Relevant Code:

use bevy::prelude::*;
use bevy_ecs_tilemap::{TilemapPlugin, TilemapBundle};

fn main() {
    App::new()
        .add_plugins((DefaultPlugins, TilemapPlugin))
        .add_state::<ExampleState>()
        .add_systems(Startup, (spawn_camera, spawn_tilemap_example))
        .add_systems(OnExit(ExampleState::State1), despawn_tilemap_example)
        .add_systems(OnEnter(ExampleState::State2), spawn_sprite_example)
        .add_systems(Update, change_example_state)
        .run();
}

#[derive(States, Default, Hash, Clone, Copy, Eq, PartialEq, Debug)]
pub enum ExampleState {
    #[default]
    State1,
    State2,
}

#[derive(Component)]
pub struct ExampleTilemap;

pub fn spawn_camera(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
}

pub fn spawn_tilemap_example(mut commands: Commands) {
    info!("spawn_tilemap_example");
    commands.spawn((
        ExampleTilemap,
        TilemapBundle {
            ..default()
        },
    ));
}

pub fn despawn_tilemap_example(query: Query<Entity, With<ExampleTilemap>>, mut commands: Commands) {
    info!("despawn_tilemap_example");
    commands.entity(query.single()).despawn();
}

// TODO: Determine why this panics after despawning `TilemapBundle` components
pub fn spawn_sprite_example(mut commands: Commands) {
    info!("spawn_sprite_example");
    commands.spawn(SpriteBundle {
        ..default()
    });
}

pub fn change_example_state(state: Res<State<ExampleState>>, mut next_state: ResMut<NextState<ExampleState>>) {
    if state.get() == &ExampleState::State1 {
        info!("changing state");
        next_state.set(ExampleState::State2);
    }
}

This code causes app to panic when using the main branch of bevy_ecs_tilemap + bevy 0.12

This code does not cause app to panic when targeting bevy 0.11.3 and bevy_ecs_tilemap 0.11.0

This code does not panic if SpriteBundle is spawned with a texture.

panic occurs here in bevy_render:

let receiver = world.get_resource::<RenderToMainAppReceiver>().unwrap();
receiver.0.recv().await.unwrap()

attempting to unwrap recv().await.unwrap() fails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant