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

LdtkPlugin cannot be ran in Testing Environment #327

Open
divark opened this issue Jul 10, 2024 · 0 comments
Open

LdtkPlugin cannot be ran in Testing Environment #327

divark opened this issue Jul 10, 2024 · 0 comments

Comments

@divark
Copy link

divark commented Jul 10, 2024

Problem

When running this library (mimicking the basic example) in a Test, the test fails due to Resources existing relating to Rendering:

thread 'plugin_does_not_crash_without_render' panicked at /home/divark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.13.2/src/system/system_param.rs:570:17:
Resource requested by bevy_ecs_ldtk::systems::process_ldtk_levels does not exist: bevy_asset::assets::Assets<bevy_sprite::texture_atlas::TextureAtlasLayout>
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_ecs_ldtk::systems::process_ldtk_levels`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!

Steps to Reproduce

  1. Clone this library.
  2. Copy the test code below into tests/no_render.rs
  3. Run cargo test --test no_render --no-default-features --features=internal_levels
  4. Observe the error message mentioned above.

The Test Code

use bevy::prelude::*;
use bevy_ecs_ldtk::prelude::*;

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn(LdtkWorldBundle {
        ldtk_handle: asset_server.load("my_project.ldtk"),
        ..Default::default()
    });
}

#[test]
fn plugin_does_not_crash_without_render() {
    let mut app = App::new();

    app.add_plugins(MinimalPlugins);

    app.add_plugins(AssetPlugin::default());
    app.add_plugins(ImagePlugin::default());
    app.add_plugins(LdtkPlugin);

    app.add_systems(Startup, setup);
    app.insert_resource(LevelSelection::index(0));

    let mut num_entities = 0;
    loop {
        app.update();

        num_entities = app
            .world
            .query::<&EntityInstance>()
            .iter(&app.world)
            .count();

        if num_entities != 0 {
            break;
        }
    }

    assert_ne!(num_entities, 0);
}
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

No branches or pull requests

1 participant