Skip to content

crash when spawning the same scene multiple times #1019

@mockersf

Description

@mockersf

Bevy version

git 1398d78

Operating system & version

macOS 10.15.7

What you did

I modified the example load_gltf.rs to spawn the same gltf scene twice.

use bevy::prelude::*;

fn main() {
    App::build()
        .add_resource(Msaa { samples: 4 })
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .run();
}

fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
    commands
        .spawn_scene(dbg!(
            asset_server.load("models/FlightHelmet/FlightHelmet.gltf")
        ))
        .spawn_scene(dbg!(
            asset_server.load("models/FlightHelmet/FlightHelmet.gltf")
        ))
        .spawn(LightBundle {
            transform: Transform::from_translation(Vec3::new(4.0, 5.0, 4.0)),
            ..Default::default()
        })
        .spawn(Camera3dBundle {
            transform: Transform::from_translation(Vec3::new(0.7, 0.7, 1.0))
                .looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::unit_y()),
            ..Default::default()
        });
}

What you expected to happen

The scene should have been displayed twice at the same position.
As SceneSpawner has a field spawned_scenes: HashMap<Handle<Scene>, Vec<InstanceId>>, I expected it possible to have several instance of the same scene

What actually happened

the game crashes:

RUST_BACKTRACE=1 cargo run --example load_gltf
    Finished dev [unoptimized + debuginfo] target(s) in 0.40s
     Running `target/debug/examples/load_gltf`
[examples/3d/load_gltf.rs:13] asset_server.load("models/FlightHelmet/FlightHelmet.gltf") = StrongHandle<Scene>(AssetPathId(AssetPathId(SourcePathId(11808433346598174139), LabelId(6298619649789039366))))
[examples/3d/load_gltf.rs:16] asset_server.load("models/FlightHelmet/FlightHelmet.gltf") = StrongHandle<Scene>(AssetPathId(AssetPathId(SourcePathId(11808433346598174139), LabelId(6298619649789039366))))
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: EntityNotFound(13v0)', crates/bevy_scene/src/scene_spawner.rs:196:22
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
   1: core::panicking::panic_fmt
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:85
   2: core::option::expect_none_failed
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/option.rs:1234
   3: core::result::Result<T,E>::unwrap
             at /Users/francois/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:973
   4: bevy_scene::scene_spawner::SceneSpawner::spawn_sync
             at ./crates/bevy_scene/src/scene_spawner.rs:194
   5: bevy_scene::scene_spawner::SceneSpawner::spawn_queued_scenes
             at ./crates/bevy_scene/src/scene_spawner.rs:260
   6: bevy_scene::scene_spawner::scene_spawner_system
             at ./crates/bevy_scene/src/scene_spawner.rs:290
   7: core::ops::function::FnMut::call_mut
             at /Users/francois/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:150
   8: bevy_ecs::system::into_thread_local::<impl bevy_ecs::system::into_system::IntoSystem<(&mut bevy_ecs::core::world::World,&mut bevy_ecs::resource::resources::Resources),bevy_ecs::system::into_thread_local::ThreadLocalSystemFn> for F>::system::{{closure}}
             at ./crates/bevy_ecs/src/system/into_thread_local.rs:69
   9: <alloc::boxed::Box<F> as core::ops::function::FnMut<A>>::call_mut
             at /Users/francois/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1049
  10: <bevy_ecs::system::into_thread_local::ThreadLocalSystemFn as bevy_ecs::system::system::System>::run_thread_local
             at ./crates/bevy_ecs/src/system/into_thread_local.rs:49
  11: bevy_ecs::schedule::parallel_executor::ExecutorStage::run
             at ./crates/bevy_ecs/src/schedule/parallel_executor.rs:506
  12: bevy_ecs::schedule::parallel_executor::ParallelExecutor::run
             at ./crates/bevy_ecs/src/schedule/parallel_executor.rs:73
  13: bevy_app::app::App::update
             at ./crates/bevy_app/src/app.rs:65
  14: bevy_winit::winit_runner::{{closure}}
             at ./crates/bevy_winit/src/lib.rs:360
  15: <alloc::boxed::Box<F> as core::ops::function::FnMut<A>>::call_mut
             at /Users/francois/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1049
  16: <winit::platform_impl::platform::app_state::EventLoopHandler<T> as winit::platform_impl::platform::app_state::EventHandler>::handle_nonuser_event
             at /Users/francois/.cargo/registry/src/gitproxy.zycloud.tk-1ecc6299db9ec823/winit-0.23.0/src/platform_impl/macos/app_state.rs:71
  17: winit::platform_impl::platform::app_state::Handler::handle_nonuser_event
             at /Users/francois/.cargo/registry/src/gitproxy.zycloud.tk-1ecc6299db9ec823/winit-0.23.0/src/platform_impl/macos/app_state.rs:173
  18: winit::platform_impl::platform::app_state::AppState::cleared
             at /Users/francois/.cargo/registry/src/gitproxy.zycloud.tk-1ecc6299db9ec823/winit-0.23.0/src/platform_impl/macos/app_state.rs:331
  19: winit::platform_impl::platform::observer::control_flow_end_handler
             at /Users/francois/.cargo/registry/src/gitproxy.zycloud.tk-1ecc6299db9ec823/winit-0.23.0/src/platform_impl/macos/observer.rs:135
  20: ___CFRunLoopRun
  21: ___CFRunLoopRun
  22: _CFRunLoopRunSpecific
  23: _____kCFPasteboardFilenamesFlavor_block_invoke
  24: _RunCurrentEventLoopInMode
  25: _ReceiveNextEventCommon
  26: __BlockUntilNextEventMatchingListInModeWithFilter
  27: __DPSNextEvent
  28: -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
  29: -[NSApplication run]
  30: <() as objc::message::MessageArguments>::invoke
             at /Users/francois/.cargo/registry/src/gitproxy.zycloud.tk-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:128
  31: objc::message::platform::send_unverified
             at /Users/francois/.cargo/registry/src/gitproxy.zycloud.tk-1ecc6299db9ec823/objc-0.2.7/src/message/apple/mod.rs:27
  32: objc::message::send_message
             at /Users/francois/.cargo/registry/src/gitproxy.zycloud.tk-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:178
  33: winit::platform_impl::platform::event_loop::EventLoop<T>::run_return
             at /Users/francois/.cargo/registry/src/gitproxy.zycloud.tk-1ecc6299db9ec823/winit-0.23.0/src/platform_impl/macos/event_loop.rs:106
  34: winit::platform_impl::platform::event_loop::EventLoop<T>::run
             at /Users/francois/.cargo/registry/src/gitproxy.zycloud.tk-1ecc6299db9ec823/winit-0.23.0/src/platform_impl/macos/event_loop.rs:93
  35: winit::event_loop::EventLoop<T>::run
             at /Users/francois/.cargo/registry/src/gitproxy.zycloud.tk-1ecc6299db9ec823/winit-0.23.0/src/event_loop.rs:154
  36: bevy_winit::run
             at ./crates/bevy_winit/src/lib.rs:120
  37: bevy_winit::winit_runner
             at ./crates/bevy_winit/src/lib.rs:368
  38: core::ops::function::Fn::call
             at /Users/francois/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:70
  39: <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call
             at /Users/francois/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1056
  40: bevy_app::app::App::run
             at ./crates/bevy_app/src/app.rs:93
  41: bevy_app::app_builder::AppBuilder::run
             at ./crates/bevy_app/src/app_builder.rs:44
  42: load_gltf::main
             at ./examples/3d/load_gltf.rs:4
  43: core::ops::function::FnOnce::call_once
             at /Users/francois/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Additional information

I would have liked to be able to modify the scene prior to spawning it, for example to translate / rotate the model, or add a component to some of the entities but I didn't find how to do that

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsP-CrashA sudden unexpected crash

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions