NiklasEi / bevy_asset_loader

Bevy plugin helping with asset loading and organization
Apache License 2.0
459 stars 52 forks source link

Bevy 0.10.1, crash when changing the exit condition #121

Closed zwazel closed 1 year ago

zwazel commented 1 year ago

In the newest bevy release, they fixed that the game crashes when changing the exit_condition in the WindowPlugin 7950. When trying to run my game with exit_condition being anything else than OnAllClosed, it crashes.

Interstingly, it first says 4 times that the loading state is done: 2023-04-01T11:07:27.685445Z INFO bevy_asset_loader::loading_state::systems: Loading state 'MainMenu' is done 2023-04-01T11:07:27.685494Z INFO bevy_asset_loader::loading_state::systems: Loading state 'MainMenu' is done 2023-04-01T11:07:27.685531Z INFO bevy_asset_loader::loading_state::systems: Loading state 'MainMenu' is done 2023-04-01T11:07:27.685561Z INFO bevy_asset_loader::loading_state::systems: Loading state 'MainMenu' is done

The error: 2023-04-01T11:07:27.686809Z WARN bevy_ecs::schedule::schedule: schedule with label LoadingStateSchedule(DoneLoadingMainMenu) not found thread 'main' panicked at 'The schedule with the label LoadingStateSchedule(DoneLoadingMainMenu) was not found.', C:\Users\zwaze\.cargo\registry\src\github.com-1ecc6299db9ec823\bevy_ecs-0.10.1\src\world\mod.rs:1743:32

NiklasEi commented 1 year ago

I cannot reproduce your error message, but I also get panics when changing the exit_condition. Thank you for the heads-up.

zwazel commented 1 year ago

I made following mini bevy project, when I try to run it I get the same crash as mentioned before. Do you here also not get the error? And thanks a lot for this project btw, helps a lot :)

Cargo.toml:

[package]
name = "reproduce_exit_condition_crash"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { version = "0.10.1" }
bevy_asset_loader = "0.16.0"

# Enable a small amount of optimization in debug mode
[profile.dev]
opt-level = 1

# Enable a lot of optimization in release mode
[profile.release]
codegen-units = 1

# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"]
opt-level = 3

main.rs:

use bevy::DefaultPlugins;
use bevy::prelude::*;
use bevy::window::ExitCondition;
use bevy_asset_loader::prelude::*;

#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
enum AppState {
    #[default]
    LoadMainMenu,
    MainMenu,
}

fn main() {
    let mut app = App::new();
    app.add_state::<AppState>()
        .add_loading_state(
            LoadingState::new(AppState::LoadMainMenu)
                .continue_to_state(AppState::MainMenu),
        );

    app.add_plugins(DefaultPlugins.set(WindowPlugin {
        primary_window: Some(Window {
            title: format!("Reproduce Crash"),
            ..default()
        }),
        exit_condition: ExitCondition::DontExit, // Crash
        ..default()
    }));

    app.run();
}
NiklasEi commented 1 year ago

I investigated this a bit more last weekend. The underlying problem seems to be in Bevy 0.10 (see linked issue above).

I will fix it for bevy_asset_loader with a workaround, so we don't need to wait for Bevy 0.11.