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

2D examples crash on exit with "Couldn't get swap chain texture" #11734

Closed
spectria-limina opened this issue Feb 6, 2024 · 15 comments · Fixed by #12978
Closed

2D examples crash on exit with "Couldn't get swap chain texture" #11734

spectria-limina opened this issue Feb 6, 2024 · 15 comments · Fixed by #12978
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior O-Linux Specific to the Linux desktop operating system P-Crash A sudden unexpected crash

Comments

@spectria-limina
Copy link
Contributor

Bevy version

main, commit 2a1ebc4

[Optional] Relevant system information

2024-02-06T02:02:22.879898Z  INFO bevy_render::renderer: AdapterInfo { name: "AMD Radeon Graphics (RADV GFX1103_R1)", vendor: 4098, device: 5567, device_type: IntegratedGpu, driver: "radv", driver_info: "Mesa 23.3.3", backend: Vulkan }
2024-02-06T02:02:23.344221Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux 39 Fedora Linux", kernel: "6.6.13-200.fc39.x86_64", cpu: "", core_count: "8", memory: "58.5 GiB" }

What you did

cargo run --example sprite

What went wrong

Everything runs fine until I close the window, then:

thread 'Compute Task Pool (2)' panicked at crates/bevy_render/src/view/window/mod.rs:372:21:
Couldn't get swap chain texture, operation unrecoverable: The swap chain has been lost and needs to be recreated
stack backtrace:
   0: rust_begin_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
   2: bevy_render::view::window::prepare_windows
             at ./crates/bevy_render/src/view/window/mod.rs:372:21
   3: core::ops::function::FnMut::call_mut
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:166:5
   4: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:294:13
   5: <Func as bevy_ecs::system::function_system::SystemParamFunction<fn(F0,F1,F2,F3,F4,F5,F6,F7,F8) .> Out>>::run::call_inner
             at ./crates/bevy_ecs/src/system/function_system.rs:661:21
   6: <Func as bevy_ecs::system::function_system::SystemParamFunction<fn(F0,F1,F2,F3,F4,F5,F6,F7,F8) .> Out>>::run
             at ./crates/bevy_ecs/src/system/function_system.rs:664:17
   7: <bevy_ecs::system::function_system::FunctionSystem<Marker,F> as bevy_ecs::system::system::System>::run_unsafe
             at ./crates/bevy_ecs/src/system/function_system.rs:504:19
   8: bevy_ecs::schedule::executor::multi_threaded::MultiThreadedExecutor::spawn_system_task::{{closure}}::{{closure}}
             at ./crates/bevy_ecs/src/schedule/executor/multi_threaded.rs:535:26
   9: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
  10: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panic/unwind_safe.rs:272:9
  11: std::panicking::try::do_call
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40
  12: __rust_try
  13: std::panicking::try
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19
  14: std::panic::catch_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14
  15: bevy_ecs::schedule::executor::multi_threaded::MultiThreadedExecutor::spawn_system_task::{{closure}}
             at ./crates/bevy_ecs/src/schedule/executor/multi_threaded.rs:530:23
  16: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::future::future::Future>::poll
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panic/unwind_safe.rs:297:9
  17: <futures_lite::future::CatchUnwind<F> as core::future::future::Future>::poll::{{closure}}
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.2.0/src/future.rs:588:42
  18: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panic/unwind_safe.rs:272:9
  19: std::panicking::try::do_call
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40
  20: __rust_try
  21: std::panicking::try
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19
  22: std::panic::catch_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14
  23: <futures_lite::future::CatchUnwind<F> as core::future::future::Future>::poll
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.2.0/src/future.rs:588:9
  24: async_executor::Executor::spawn::{{closure}}
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.8.0/src/lib.rs:158:20
  25: async_task::raw::RawTask<F,T,S,M>::run::{{closure}}
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.0/src/raw.rs:550:21
  26: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
  27: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panic/unwind_safe.rs:272:9
  28: std::panicking::try::do_call
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40
  29: __rust_try
  30: std::panicking::try
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19
  31: std::panic::catch_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14
  32: async_task::raw::RawTask<F,T,S,M>::run
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.0/src/raw.rs:549:23
  33: async_task::runnable::Runnable<M>::run
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.0/src/runnable.rs:781:18
  34: async_executor::Executor::run::{{closure}}::{{closure}}
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.8.0/src/lib.rs:254:21
  35: <futures_lite::future::Or<F1,F2> as core::future::future::Future>::poll
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.2.0/src/future.rs:449:33
  36: async_executor::Executor::run::{{closure}}
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.8.0/src/lib.rs:261:32
  37: futures_lite::future::block_on::{{closure}}
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.2.0/src/future.rs:99:19
  38: std::thread::local::LocalKey<T>::try_with
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/local.rs:270:16
  39: std::thread::local::LocalKey<T>::with
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/local.rs:246:9
  40: futures_lite::future::block_on
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.2.0/src/future.rs:78:5
  41: bevy_tasks::task_pool::TaskPool::new_internal::{{closure}}::{{closure}}::{{closure}}::{{closure}}
             at ./crates/bevy_tasks/src/task_pool.rs:180:37
  42: std::panicking::try::do_call
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40
  43: __rust_try
  44: std::panicking::try
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19
  45: std::panic::catch_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14
  46: bevy_tasks::task_pool::TaskPool::new_internal::{{closure}}::{{closure}}::{{closure}}
             at ./crates/bevy_tasks/src/task_pool.rs:174:43
  47: std::thread::local::LocalKey<T>::try_with
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/local.rs:270:16
  48: std::thread::local::LocalKey<T>::with
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/local.rs:246:9
  49: bevy_tasks::task_pool::TaskPool::new_internal::{{closure}}::{{closure}}
             at ./crates/bevy_tasks/src/task_pool.rs:167:25
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Encountered a panic in system `bevy_render::view::window::prepare_windows`!
thread 'main' panicked at crates/bevy_render/src/pipelined_rendering.rs:145:45:
called `Result::unwrap()` on an `Err` value: RecvError
stack backtrace:
   0: rust_begin_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/result.rs:1653:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/result.rs:1077:23
   4: bevy_render::pipelined_rendering::update_rendering::{{closure}}::{{closure}}::{{closure}}
             at ./crates/bevy_render/src/pipelined_rendering.rs:145:21
   5: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::future::future::Future>::poll
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panic/unwind_safe.rs:297:9
   6: <futures_lite::future::CatchUnwind<F> as core::future::future::Future>::poll::{{closure}}
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.2.0/src/future.rs:588:42
   7: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panic/unwind_safe.rs:272:9
   8: std::panicking::try::do_call
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40
   9: __rust_try
  10: std::panicking::try
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19
  11: std::panic::catch_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14
  12: <futures_lite::future::CatchUnwind<F> as core::future::future::Future>::poll
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.2.0/src/future.rs:588:9
  13: async_executor::Executor::spawn::{{closure}}
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.8.0/src/lib.rs:158:20
  14: async_task::raw::RawTask<F,T,S,M>::run::{{closure}}
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.0/src/raw.rs:550:21
  15: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
  16: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panic/unwind_safe.rs:272:9
  17: std::panicking::try::do_call
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40
  18: __rust_try
  19: std::panicking::try
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19
  20: std::panic::catch_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14
  21: async_task::raw::RawTask<F,T,S,M>::run
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.0/src/raw.rs:549:23
  22: async_task::runnable::Runnable<M>::run
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.0/src/runnable.rs:781:18
  23: async_executor::Executor::run::{{closure}}::{{closure}}
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.8.0/src/lib.rs:254:21
  24: <futures_lite::future::Or<F1,F2> as core::future::future::Future>::poll
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.2.0/src/future.rs:449:33
  25: async_executor::Executor::run::{{closure}}
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.8.0/src/lib.rs:261:32
  26: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::future::future::Future>::poll
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panic/unwind_safe.rs:297:9
  27: <futures_lite::future::CatchUnwind<F> as core::future::future::Future>::poll::{{closure}}
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.2.0/src/future.rs:588:42
  28: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panic/unwind_safe.rs:272:9
  29: std::panicking::try::do_call
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40
  30: __rust_try
  31: std::panicking::try
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19
  32: std::panic::catch_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14
  33: <futures_lite::future::CatchUnwind<F> as core::future::future::Future>::poll
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.2.0/src/future.rs:588:9
  34: bevy_tasks::task_pool::TaskPool::execute_global_scope::{{closure}}::{{closure}}
             at ./crates/bevy_tasks/src/task_pool.rs:502:22
  35: <futures_lite::future::Or<F1,F2> as core::future::future::Future>::poll
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.2.0/src/future.rs:446:33
  36: bevy_tasks::task_pool::TaskPool::execute_global_scope::{{closure}}
             at ./crates/bevy_tasks/src/task_pool.rs:506:41
  37: bevy_tasks::task_pool::TaskPool::scope_with_executor_inner::{{closure}}
             at ./crates/bevy_tasks/src/task_pool.rs:433:89
  38: futures_lite::future::block_on::{{closure}}
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.2.0/src/future.rs:99:19
  39: std::thread::local::LocalKey<T>::try_with
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/local.rs:270:16
  40: std::thread::local::LocalKey<T>::with
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/local.rs:246:9
  41: futures_lite::future::block_on
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.2.0/src/future.rs:78:5
  42: bevy_tasks::task_pool::TaskPool::scope_with_executor_inner
             at ./crates/bevy_tasks/src/task_pool.rs:389:13
  43: bevy_tasks::task_pool::TaskPool::scope_with_executor::{{closure}}
             at ./crates/bevy_tasks/src/task_pool.rs:320:17
  44: std::thread::local::LocalKey<T>::try_with
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/local.rs:270:16
  45: std::thread::local::LocalKey<T>::with
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/thread/local.rs:246:9
  46: bevy_tasks::task_pool::TaskPool::scope_with_executor
             at ./crates/bevy_tasks/src/task_pool.rs:316:9
  47: bevy_render::pipelined_rendering::update_rendering::{{closure}}
             at ./crates/bevy_render/src/pipelined_rendering.rs:141:30
  48: bevy_ecs::world::World::resource_scope
             at ./crates/bevy_ecs/src/world/mod.rs:1672:22
  49: bevy_render::pipelined_rendering::update_rendering
             at ./crates/bevy_render/src/pipelined_rendering.rs:138:5
  50: core::ops::function::Fn::call
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:79:5
  51: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/alloc/src/boxed.rs:2021:9
  52: bevy_app::app::SubApp::extract
             at ./crates/bevy_app/src/app.rs:170:9
  53: bevy_app::app::App::update
             at ./crates/bevy_app/src/app.rs:268:13
  54: bevy_winit::run_app_update_if_should
             at ./crates/bevy_winit/src/lib.rs:717:9
  55: bevy_winit::handle_winit_event
             at ./crates/bevy_winit/src/lib.rs:597:21
  56: bevy_winit::winit_runner::{{closure}}
             at ./crates/bevy_winit/src/lib.rs:281:9
  57: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:294:13
  58: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:294:13
  59: winit::platform_impl::platform::x11::EventLoop<T>::single_iteration
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.10/src/platform_impl/linux/x11/mod.rs:608:17
  60: winit::platform_impl::platform::x11::EventLoop<T>::poll_events_with_timeout
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.10/src/platform_impl/linux/x11/mod.rs:547:9
  61: winit::platform_impl::platform::x11::EventLoop<T>::pump_events
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.10/src/platform_impl/linux/x11/mod.rs:453:13
  62: winit::platform_impl::platform::x11::EventLoop<T>::run_on_demand
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.10/src/platform_impl/linux/x11/mod.rs:414:19
  63: winit::platform_impl::platform::EventLoop<T>::run_on_demand
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.10/src/platform_impl/linux/mod.rs:821:56
  64: winit::platform_impl::platform::EventLoop<T>::run
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.10/src/platform_impl/linux/mod.rs:814:9
  65: winit::event_loop::EventLoop<T>::run
             at /home/alercah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.10/src/event_loop.rs:249:9
  66: bevy_winit::winit_runner
             at ./crates/bevy_winit/src/lib.rs:296:23
  67: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
  68: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
  69: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/alloc/src/boxed.rs:2007:9
  70: bevy_app::app::App::run
             at ./crates/bevy_app/src/app.rs:308:9
  71: sprite::main
             at ./examples/2d/sprite.rs:6:5
  72: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
@spectria-limina spectria-limina added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Feb 6, 2024
@spectria-limina
Copy link
Contributor Author

This stack trace is pretty cursed, with the nested catch_unwind calls.

@rparrett rparrett added A-Rendering Drawing game state to the screen P-Crash A sudden unexpected crash and removed S-Needs-Triage This issue needs to be labelled labels Feb 6, 2024
@Friz64
Copy link
Contributor

Friz64 commented Feb 6, 2024

Bisected to #11660. cc @hymm

Seems to only happen on X11 for me (ran through XWayland), Wayland directly works fine. I am running GNOME Wayland.

@hymm
Copy link
Contributor

hymm commented Feb 6, 2024

I bet it's because we're not waiting for the render thread to finish before cleaning up the window. We probably need to add a drop check that if the render thread isn't on the main thread we should wait for the render world to be sent back before dropping the render world channels.

@hymm
Copy link
Contributor

hymm commented Feb 6, 2024

Could someone test if #11737 helps with this issue?

@Friz64
Copy link
Contributor

Friz64 commented Feb 6, 2024

Unfortunately, I'm still getting the same issue.

@hymm
Copy link
Contributor

hymm commented Feb 6, 2024

hmm, I wonder if the swap chain is already destroyed when the resource is dropped. Might need to prevent render from being run again if we're exiting the app.

@hymm
Copy link
Contributor

hymm commented Feb 7, 2024

does this branch fix this issue https://github.com/hymm/bevy/tree/no-render-if-app-exit?

@Friz64
Copy link
Contributor

Friz64 commented Feb 7, 2024

2024-02-07T07:19:09.357857Z  INFO bevy_winit::system: Closing window 0v1
exiting early
thread 'Compute Task Pool (12)' panicked at crates/bevy_render/src/view/window/mod.rs:372:21:
Couldn't get swap chain texture, operation unrecoverable: The swap chain has been lost and needs to be recreated
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_render::view::window::prepare_windows`!
friz64@arch ~/D/r/bevy ((0fb0f3f2))> git diff
diff --git a/crates/bevy_render/src/pipelined_rendering.rs b/crates/bevy_render/src/pipelined_rendering.rs
index 86acfe37c..805603a97 100644
--- a/crates/bevy_render/src/pipelined_rendering.rs
+++ b/crates/bevy_render/src/pipelined_rendering.rs
@@ -180,6 +180,7 @@ fn update_rendering(app_world: &mut World, _sub_app: &mut App) {
     // dont run render if app exit has been sent
     if let Some(app_exit) = app_world.get_resource::<Events<AppExit>>() {
         if !app_exit.is_empty() {
+            println!("exiting early");
             return;
         }
     }

The branch gets taken, but it still panics.

@hymm
Copy link
Contributor

hymm commented Feb 8, 2024

weird. 2 possibilities: either the prepare windows is panicking for render run before app exit is sent or it's taking more than 2 ticks for the app to exit, since events only live for 2 frames. Could you add a println! after the 2 if's and see if it logs something after the "exiting early"?

@Friz64
Copy link
Contributor

Friz64 commented Feb 8, 2024

Could you add a println! after the 2 if's and see if it logs something after the "exiting early"?

It does not log something.

@hymm
Copy link
Contributor

hymm commented Feb 8, 2024

That means it's most likely the first option, which I'm not sure how to fix yet.

@Friz64
Copy link
Contributor

Friz64 commented Feb 10, 2024

It now panics twice on the main branch, see: #11811 (comment)


Also, I got curious and tried directly running it in an X11 session (so, without XWayland) to see if it would behave differently, and indeed, it doesn't panic, but this error is printed instead:

2024-02-10T22:16:03.120880Z  INFO bevy_window::system: No windows are open, exiting
2024-02-10T22:16:03.121002Z  INFO bevy_winit::system: Closing window 0v1
2024-02-10T22:16:03.143735Z ERROR log: X11 error: XError {
    description: "BadWindow (invalid Window parameter)",
    error_code: 3,
    request_code: 148,
    minor_code: 1,
}    
2024-02-10T22:16:03.146932Z ERROR bevy_winit: winit event loop returned an error: os error at /home/friz64/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.10/src/platform_impl/linux/x11/mod.rs:433: Xlib error: X error: BadWindow (invalid Window parameter) (code: 3, request code: 148, minor code: 1)

I'm not sure if this is really related, as this has been reported (twice?) before #11660 got merged:

So it might just be that the panic caused by #11660 only happens when running through XWayland. Oh how I love all this. Big headache.

@mempler
Copy link

mempler commented Feb 17, 2024

Seems like this issue ended up in 0.13.0 aswell

@james7132 james7132 added the O-Linux Specific to the Linux desktop operating system label Mar 17, 2024
Ablesius added a commit to Ablesius/rustysnake that referenced this issue Mar 28, 2024
WHY WIP:
`_setup_camera` commented out for the moment because we observed the
error mentioned in the comment
(bevyengine/bevy#11734).
With `do_nothing`, we get this:

```
2024-03-28T11:58:43.553731Z ERROR log: X11 error: XError {
    description: "BadWindow (invalid Window parameter)",
    error_code: 3,
    request_code: 148,
    minor_code: 1,
}
2024-03-28T11:58:43.567517Z ERROR bevy_winit: winit event loop returned an error: os error at /home/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/linux/x11/mod.rs:427: Xlib error: X error: BadWindow (invalid Window parameter) (code: 3, request code: 148, minor code: 1)
```
@Ablesius
Copy link

Hi there, I ran into the same issue and noticed an interesting difference in behaviour:

I got the panic specifically when trying to add a camera to the Startup system:

fn main() {
    App::new()
        // this crashes when closing the window with https://github.com/bevyengine/bevy/issues/11734
        .add_systems(Startup, setup_camera)
        .add_plugins(DefaultPlugins)
        .run();
}

fn setup_camera(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
}

When I instead replace the setup_camera function with an empty do_nothing function ( fn do_nothing() {} ), then I get a rather benign-looking error on closing:

2024-03-28T11:58:43.553731Z ERROR log: X11 error: XError {
    description: "BadWindow (invalid Window parameter)",
    error_code: 3,
    request_code: 148,
    minor_code: 1,
}    
2024-03-28T11:58:43.567517Z ERROR bevy_winit: winit event loop returned an error: os error at /home/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/linux/x11/mod.rs:427: Xlib error: X error: BadWindow (invalid Window parameter) (code: 3, request code: 148, minor code: 1)

Maybe that second error is also unwanted, not sure (every single GUI application I've ever seen seems to throw errors regularly when running normal) but at least it's something else; hope that helps in tracking stuff down! :)

Ablesius added a commit to Ablesius/rustysnake that referenced this issue Mar 28, 2024
This doesn't do anything useful. Commit just kept around in case I need
to revisit this.

`_setup_camera` commented out for the moment because we observed the
error mentioned in the comment
(bevyengine/bevy#11734).
With `do_nothing`, we get this:

```
2024-03-28T11:58:43.553731Z ERROR log: X11 error: XError {
    description: "BadWindow (invalid Window parameter)",
    error_code: 3,
    request_code: 148,
    minor_code: 1,
}
2024-03-28T11:58:43.567517Z ERROR bevy_winit: winit event loop returned an error: os error at /home/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/linux/x11/mod.rs:427: Xlib error: X error: BadWindow (invalid Window parameter) (code: 3, request code: 148, minor code: 1)
```
@s-puig
Copy link
Contributor

s-puig commented Mar 28, 2024

We already identified the issue for a while and #12524 is waiting for review.

Until then a workaround is disabling pipelined rendering:

App::new()
    .add_plugins(
        DefaultPlugins.build()
            .disable::<PipelinedRenderingPlugin>()
    )

github-merge-queue bot pushed a commit that referenced this issue Apr 30, 2024
… using pipelined rendering (#12978)

# Objective

A `RawWindowHandle` is only valid as long as the window it was retrieved
from is alive. Extend the lifetime of the window, so that the
`RawWindowHandle` doesn't outlive it, and bevy doesn't crash when
closing a window a pipelined renderer is drawing to.

- Fix #11236
- Fix #11150
- Fix #11734
- Alternative to / Closes #12524

## Solution

Introduce a `WindowWrapper` that takes ownership of the window. Require
it to be used when constructing a `RawHandleWrapper`. This forces
windowing backends to store their window in this wrapper.

The `WindowWrapper` is implemented by storing the window in an `Arc<dyn
Any + Send + Sync>`.

We use dynamic dispatch here because we later want the
`RawHandleWrapper` to be able dynamically hold a reference to any
windowing backend's window.

But alas, the `WindowWrapper` itself is still practically invisible to
windowing backends, because it implements `Deref` to the underlying
window, by storing its type in a `PhantomData`.

---

## Changelog

### Added

- Added `WindowWrapper`, which windowing backends are now required to
use to store their underlying window.

### Fixed

- Fixed a safety problem which caused crashes when closing bevy windows
when using pipelined rendering.

## Migration Guide

- Windowing backends now need to store their window in the new
`WindowWrapper`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior O-Linux Specific to the Linux desktop operating system P-Crash A sudden unexpected crash
Projects
None yet
8 participants