bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.35k stars 3.49k forks source link

Adding and removing a scene bundle entity in the same frame causes a panic #8331

Closed alice-i-cecile closed 5 months ago

alice-i-cecile commented 1 year ago

Bevy version

0.10.1

What you did

Spawn a scene bundle, and despawn it in the same frame.

What went wrong

thread 'main' panicked at 'Entity 7826v23 does not exist', /home/alice/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_ecs-0.10.1/src/world/mod.rs:274:32
stack backtrace:
   0: rust_begin_unwind
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/panicking.rs:64:14
   2: <bevy_hierarchy::child_builder::AddChild as bevy_ecs::system::commands::Command>::write
   3: bevy_scene::scene_spawner::SceneSpawner::set_scene_instance_parent_sync
   4: bevy_ecs::world::World::resource_scope
   5: <bevy_ecs::system::exclusive_function_system::ExclusiveFunctionSystem<Marker,F> as bevy_ecs::system::system::System>::run
   6: async_task::raw::RawTask<F,T,S,M>::run
   7: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
   8: <futures_lite::future::Or<F1,F2> as core::future::future::Future>::poll
   9: bevy_tasks::task_pool::TaskPool::scope_with_executor_inner::{{closure}}
  10: std::thread::local::LocalKey<T>::with
  11: bevy_tasks::task_pool::TaskPool::scope_with_executor_inner
  12: <bevy_ecs::schedule::executor::multi_threaded::MultiThreadedExecutor as bevy_ecs::schedule::executor::SystemExecutor>::run
  13: bevy_ecs::world::World::run_schedule_ref
  14: <bevy_ecs::system::exclusive_function_system::ExclusiveFunctionSystem<Marker,F> as bevy_ecs::system::system::System>::run
  15: <bevy_ecs::schedule::executor::single_threaded::SingleThreadedExecutor as bevy_ecs::schedule::executor::SystemExecutor>::run
  16: bevy_ecs::world::World::run_schedule_ref
  17: bevy_app::app::App::update
  18: bevy_winit::winit_runner::{{closure}}
  19: winit::platform_impl::platform::x11::EventLoop<T>::run_return::single_iteration
  20: winit::platform_impl::platform::x11::EventLoop<T>::run_return
  21: winit::platform_impl::platform::x11::EventLoop<T>::run
  22: winit::platform_impl::platform::EventLoop<T>::run
  23: winit::event_loop::EventLoop<T>::run
  24: bevy_winit::run
  25: bevy_winit::winit_runner
  26: core::ops::function::Fn::call
  27: bevy_app::app::App::run
  28: emergence_game::main

Additional information

I suspect we're not correctly validating entity references before calling entity_mut somewhere in our scene bundle system.

s-puig commented 5 months ago

Can you still reproduce this or provide an example? No luck so far on 2ae7b4c7ac8cc3dd110b201f3df53ae7bfef304b

alice-i-cecile commented 5 months ago

I suspect this is no longer reproducible. Closing out.