Skip to content

Panic "RefCell already borrowed" when closing window immediately after opening #21319

@kumikaya

Description

@kumikaya

Bevy version and features

0.17.1

What you did

  1. Ran cargo run --example mesh2d
  2. Closed the window immediately after it appeared

What went wrong

thread 'main' panicked at C:\Users\kumikaya\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\std\src\thread\local.rs:559:38:
RefCell already borrowed
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/1159e78c4747b02ef996e55082b704c09b970588/library\std\src\panicking.rs:697
   1: core::panicking::panic_fmt
             at /rustc/1159e78c4747b02ef996e55082b704c09b970588/library\core\src\panicking.rs:75
   2: core::cell::panic_already_borrowed::do_panic::runtime
             at /rustc/1159e78c4747b02ef996e55082b704c09b970588/library\core\src\panic.rs:218
   3: core::cell::panic_already_borrowed
             at /rustc/1159e78c4747b02ef996e55082b704c09b970588/library\core\src\panic.rs:223
   4: core::cell::RefCell<bevy_winit::winit_windows::WinitWindows>::borrow_mut
             at C:\Users\kumikaya\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\cell.rs:1089
   5: std::thread::local::impl$6::with_borrow_mut::closure$0<bevy_winit::winit_windows::WinitWindows,bevy_winit::system::despawn_windows::closure_env$0,tuple$<> >
             at C:\Users\kumikaya\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:559
   6: std::thread::local::LocalKey<core::cell::RefCell<bevy_winit::winit_windows::WinitWindows> >::try_with<core::cell::RefCell<bevy_winit::winit_windows::WinitWindows>,std::thread::local::impl$6::with_borrow_mut::closure_env$0<bevy_winit::winit_windows::WinitWi
             at C:\Users\kumikaya\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:315
   7: std::thread::local::LocalKey<core::cell::RefCell<bevy_winit::winit_windows::WinitWindows> >::with<core::cell::RefCell<bevy_winit::winit_windows::WinitWindows>,std::thread::local::impl$6::with_borrow_mut::closure_env$0<bevy_winit::winit_windows::WinitWindow
             at C:\Users\kumikaya\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:279
   8: std::thread::local::LocalKey<core::cell::RefCell<bevy_winit::winit_windows::WinitWindows> >::with_borrow_mut<bevy_winit::winit_windows::WinitWindows,bevy_winit::system::despawn_windows::closure_env$0,tuple$<> >
             at C:\Users\kumikaya\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:559
   9: bevy_winit::system::despawn_windows
             at .\crates\bevy_winit\src\system.rs:262
  10: core::ops::function::FnMut::call_mut<void (*)(bevy_ecs::system::query::Query<bevy_ecs::entity::Entity,bevy_ecs::query::filter::With<bevy_window::window::ClosingWindow> >,bevy_ecs::lifecycle::RemovedComponents<bevy_window::window::Window>,bevy_ecs::system::
             at C:\Users\kumikaya\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:168
  11: core::ops::function::impls::impl$3::call_mut<tuple$<bevy_ecs::system::query::Query<bevy_ecs::entity::Entity,bevy_ecs::query::filter::With<bevy_window::window::ClosingWindow> >,bevy_ecs::lifecycle::RemovedComponents<bevy_window::window::Window>,bevy_ecs::sy
             at C:\Users\kumikaya\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:301
  12: bevy_ecs::system::function_system::impl$48::run::call_inner<tuple$<>,bevy_ecs::system::query::Query<bevy_ecs::entity::Entity,bevy_ecs::query::filter::With<bevy_window::window::ClosingWindow> >,bevy_ecs::lifecycle::RemovedComponents<bevy_window::window::Win
             at .\crates\bevy_ecs\src\system\function_system.rs:926
  13: bevy_ecs::system::function_system::impl$48::run<tuple$<>,void (*)(bevy_ecs::system::query::Query<bevy_ecs::entity::Entity,bevy_ecs::query::filter::With<bevy_window::window::ClosingWindow> >,bevy_ecs::lifecycle::RemovedComponents<bevy_window::window::Window
             at .\crates\bevy_ecs\src\system\function_system.rs:929
  14: bevy_ecs::system::function_system::impl$12::run_unsafe<void (*)(bevy_ecs::system::query::Query<bevy_ecs::entity::Entity,bevy_ecs::query::filter::With<bevy_window::window::ClosingWindow> >,bevy_ecs::lifecycle::RemovedComponents<bevy_window::window::Window>,
             at .\crates\bevy_ecs\src\system\function_system.rs:711
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Encountered a panic in system `bevy_winit::system::despawn_windows`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!
error: process didn't exit successfully: `D:\build\debug\examples\mesh2d.exe` (exit code: 101)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-WindowingPlatform-agnostic interface layer to run your app inC-BugAn unexpected or incorrect behaviorO-WindowsSpecific to the Windows desktop operating systemP-CrashA sudden unexpected crashS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions