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

dropping AsyncWorld Tasks during racing operations causes panics #11

Open
databasedav opened this issue Mar 5, 2025 · 0 comments
Open

Comments

@databasedav
Copy link
Contributor

repro:

use bevy::prelude::*;
use bevy::tasks::{AsyncComputeTaskPool, Task};
use bevy_async_ecs::*;

#[derive(Component)]
struct TaskHolder(Task<()>);

#[derive(Component, Clone)]
struct Data;

fn main() {
	App::new()
		.add_plugins((DefaultPlugins, AsyncEcsPlugin))
		.add_systems(Startup, |world: &mut World| {
			let async_world = AsyncWorld::from_world(world);
			let mut entity = world.spawn(());
			let id = entity.id();
			let fut = async move {
				async_world.entity(id).wait_for::<Data>().await;
			};
			let task = AsyncComputeTaskPool::get().spawn(fut);
			entity.insert(TaskHolder(task));
		})
		.add_systems(Update, |task_holders: Query<Entity, With<TaskHolder>>, mut commands: Commands| {
			for entity in task_holders.iter() {
				commands.entity(entity).insert(Data);
				commands.entity(entity).remove::<TaskHolder>();
			}
		})
		.run();
}

gives me

thread 'main' panicked at /home/avi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5:
invariant broken: Closed(..)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_async_ecs::command::apply_commands`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!
2025-03-05T06:02:53.528311Z ERROR wgpu_hal::gles::egl: EGL 'eglDestroyContext' code 0x3008: EGL_BAD_DISPLAY error: In eglDestroyContext: Invalid EGLDisplay (0x63c2f63eb9f0)
    

thread '<unnamed>' panicked at /home/avi/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/khronos-egl-6.0.0/src/lib.rs:841:27:
called `Option::unwrap()` on a `None` value

this isn't an exact replication of what i'm actually doing in my application but it's something around these lines, e.g. storing a .wait_for Task in a component and dropping it close to when it's probably completing, the error i actually get in my application is

thread 'main' panicked at /home/avi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5:
invariant broken: Closed(..)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2025-03-05T05:57:32.532370Z  WARN bevy_ecs::world::command_queue: CommandQueue has un-applied commands being dropped. Did you forget to call SystemState::apply?
2025-03-05T05:57:32.532435Z  WARN bevy_ecs::world::command_queue: CommandQueue has un-applied commands being dropped. Did you forget to call SystemState::apply?
2025-03-05T05:57:32.532450Z  WARN bevy_ecs::world::command_queue: CommandQueue has un-applied commands being dropped. Did you forget to call SystemState::apply?

thread 'IO Task Pool (2)' panicked at /home/avi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5:
invariant broken: RecvError
Encountered a panic in system `bevy_async_ecs::command::apply_commands`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!
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