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

Process sometimes keeps running after window is closed #839

Closed
sapir opened this issue Nov 11, 2020 · 6 comments
Closed

Process sometimes keeps running after window is closed #839

sapir opened this issue Nov 11, 2020 · 6 comments
Labels
A-Core Common functionality for all bevy apps C-Bug An unexpected or incorrect behavior O-Linux Specific to the Linux desktop operating system

Comments

@sapir
Copy link
Contributor

sapir commented Nov 11, 2020

Bevy version

b113809

Operating system & version

Ubuntu 20.04

What you did

if keyboard_input.just_pressed(KeyCode::Escape) {
    app_exit_events.send(AppExit);
}

But it doesn't always happen, so I'm not sure how to reproduce it, and also I don't know if it happens if I close the window with the window manager's button.

What you expected to happen

The process should have exited immediately after the AppExit event.

What actually happened

The window closed, but the process kept running in my terminal.

Hitting CTRL-C in my terminal still closed the process.

@Moxinilian Moxinilian added C-Bug An unexpected or incorrect behavior O-Linux Specific to the Linux desktop operating system A-Windowing Platform-agnostic interface layer to run your app in A-Core Common functionality for all bevy apps and removed A-Windowing Platform-agnostic interface layer to run your app in labels Nov 11, 2020
@sapir
Copy link
Contributor Author

sapir commented Nov 12, 2020

I got a stacktrace with gdb:

#0  __pthread_clockjoin_ex (threadid=140245734483712, thread_return=0x0, clockid=<optimized out>, abstime=<optimized out>, block=<optimized out>) at pthread_join_common.c:145
#1  0x00007f8dc4445bdc in ?? () from /usr/lib/x86_64-linux-gnu/libvulkan_intel.so
#2  0x000055d20e2a88af in <gfx_backend_vulkan::window::Surface as gfx_hal::window::PresentationSurface<gfx_backend_vulkan::Backend>>::unconfigure_swapchain (self=<optimized out>, device=<optimized out>) at .../.cargo/registry/src/github.com-1ecc6299db9ec823/gfx-backend-vulkan-0.6.5/src/window.rs:484
#3  0x000055d20e12f9ce in wgpu_core::hub::Hub<B,F>::clear (self=<optimized out>, surface_guard=0x55d20f6eecf0) at .../.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-core-0.6.5/src/hub.rs:635
#4  0x000055d20e12876d in <wgpu_core::hub::Global<G> as core::ops::drop::Drop>::drop (self=0x55d20f6eec90) at .../.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-core-0.6.5/src/hub.rs:707
#5  0x000055d20e219fbd in core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#6  core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#7  alloc::sync::Arc<T>::drop_slow (self=0x55d20f9e3270) at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/sync.rs:934
#8  0x000055d20e0f1874 in <alloc::sync::Arc<T> as core::ops::drop::Drop>::drop (self=0x7f8d812f69d0) at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/sync.rs:1454
#9  core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#10 core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#11 core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#12 core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#13 core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#14 core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#15 0x000055d20e71c40b in core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#16 core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#17 <alloc::vec::Vec<T> as core::ops::drop::Drop>::drop (self=<optimized out>) at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec.rs:2638
#18 0x000055d20e7167b7 in core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#19 core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#20 core::ptr::mut_ptr::<impl *mut T>::drop_in_place (self=0x55d20f63ae50) at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mut_ptr.rs:963
#21 hashbrown::raw::Bucket<T>::drop (self=<optimized out>) at /cargo/registry/src/github.com-1ecc6299db9ec823/hashbrown-0.9.0/src/raw/mod.rs:334
#22 0x000055d20e7163ab in <hashbrown::raw::RawTable<T> as core::ops::drop::Drop>::drop (self=0x7ffcdcc5a768) at /cargo/registry/src/github.com-1ecc6299db9ec823/hashbrown-0.9.0/src/raw/mod.rs:1325
#23 0x000055d20e2e5d3c in core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#24 core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#25 core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#26 core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#27 core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#28 core::ptr::drop_in_place () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:175
#29 0x000055d20e2e87cc in winit::platform_impl::platform::x11::EventLoop<T>::run_return (self=<optimized out>, callback=...) at .../.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.23.0/src/platform_impl/linux/x11/mod.rs:380
#30 0x000055d20e2e906a in winit::platform_impl::platform::x11::EventLoop<T>::run (self=..., callback=...) at .../.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.23.0/src/platform_impl/linux/x11/mod.rs:386
#31 0x000055d20e2d0d7b in winit::platform_impl::platform::EventLoop<T>::run (self=..., callback=...) at .../.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.23.0/src/platform_impl/linux/mod.rs:642
#32 0x000055d20e2dfeab in winit::event_loop::EventLoop<T>::run (self=..., event_handler=...) at .../.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.23.0/src/event_loop.rs:154
#33 0x000055d20e2e19aa in bevy_winit::run (event_loop=..., event_handler=...) at .../.cargo/git/checkouts/bevy-f7ffde730c324c74/b113809/crates/bevy_winit/src/lib.rs:106
#34 0x000055d20e2e1c3f in bevy_winit::winit_runner (app=...) at .../.cargo/git/checkouts/bevy-f7ffde730c324c74/b113809/crates/bevy_winit/src/lib.rs:315
#35 0x000055d20e2f5c04 in core::ops::function::Fn::call () at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:70
#36 0x000055d20e71f166 in <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call (self=0x7ffcdcc5c870, args=...) at .../.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1056
#37 bevy_app::app::App::run (self=...) at .../.cargo/git/checkouts/bevy-f7ffde730c324c74/b113809/crates/bevy_app/src/app.rs:81
#38 0x000055d20e71b080 in bevy_app::app_builder::AppBuilder::run (self=<optimized out>) at .../.cargo/git/checkouts/bevy-f7ffde730c324c74/b113809/crates/bevy_app/src/app_builder.rs:43
#39 0x000055d20deb10e1 in main () at src/main.rs:384

@rmsc
Copy link
Contributor

rmsc commented Feb 16, 2021

I'm experiencing the exact same bug very consistently in one system (laptop with dual Intel + AMD GPU) after commit d5a7330. I have another system (single RTX 3070 GPU) where this doesn't happen.

The more verbose logging output I enable the rarest to non-existent the problem is. This happens both on debug and release. Very rarely does this happen on the first run after a long compile, but then happens most of the time. This suggest some sort of race condition in wgpu.

In the end I've set up a local copy of wgpu and traced this back to impl Drop for Global in wgpu_core/src/hub.rs. It hangs in the call to self.hubs.vulkan.clear():

impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
      fn drop(&mut self) {
          if !thread::panicking() {
              tracing::info!("Dropping Global");
              let mut surface_guard = self.surfaces.data.write();

              tracing::info!("DEBUGGING ATTEMPT: this is logged");

              // destroy hubs
              #[cfg(vulkan)]
              {
                  self.hubs.vulkan.clear(&mut *surface_guard, true);
              }
              #[cfg(metal)]
              {
                  self.hubs.metal.clear(&mut *surface_guard, true);
              }
              #[cfg(dx12)]
              {
                  self.hubs.dx12.clear(&mut *surface_guard, true);
              }
              #[cfg(dx11)]
              {
                  self.hubs.dx11.clear(&mut *surface_guard, true);
              }
              #[cfg(gl)]
              {
                  self.hubs.gl.clear(&mut *surface_guard, true);
              }

              tracing::info!("DEBUGGING ATTEMPT: hangs before this");

              // destroy surfaces
              for element in surface_guard.map.drain(..) {
                  if let Element::Occupied(surface, _) = element {
                      self.instance.destroy_surface(surface);
                  }
              }
          }
      }
  }

@rmsc
Copy link
Contributor

rmsc commented Feb 16, 2021

As an additional detail, this seems to only happen in x11 mode (under Xwayland) using my (default) AMD GPU (AMD Radeon HD 8800M Series).

  • If I do export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/intel_icd.x86_64.json this doesn't happen.

  • If I run with --features=wayland this doesn't seem to happen, regardless of the GPU (the AMD GPU produces visual garbage in wayland mode but doesn't hang).

Could you please check if this somehow matches your setup and/or any of the above workarounds "fix" this?

@etam
Copy link

etam commented Jan 8, 2022

I see something similar, so far only in release mode (couldn't reproduce in debug mode)

  • bevy 0.6.0
  • x11
  • only 1 gpu: Intel(R) HD Graphics 520 (SKL GT2)

gdb backtrace:

#0  0x00007fb0bcff4b2a in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007fb0bcffa004 in __pthread_clockjoin_ex () from /lib64/libc.so.6
#2  0x00007fb0ae4cb6cc in ?? () from /usr/lib64/libvulkan_intel.so
#3  0x00007fb0becd4c91 in wgpu_hal::vulkan::instance::<impl wgpu_hal::Surface<wgpu_hal::vulkan::Api> for wgpu_hal::vulkan::Surface>::unconfigure () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#4  0x00007fb0be62f680 in wgpu_core::hub::Hub<A,F>::clear () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#5  0x00007fb0be62a206 in <wgpu_core::hub::Global<G> as core::ops::drop::Drop>::drop () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#6  0x00007fb0be6970b1 in core::ptr::drop_in_place<wgpu_core::hub::Global<wgpu_core::hub::IdentityManagerFactory>> () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#7  0x00007fb0be69846c in alloc::sync::Arc<T>::drop_slow () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#8  0x00007fb0be698b9a in alloc::sync::Arc<T>::drop_slow () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#9  0x00007fb0be6e6af5 in core::ptr::drop_in_place<bevy_pbr::render::light::GlobalLightMeta> () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#10 0x00007fb0bf364045 in <bevy_ecs::storage::blob_vec::BlobVec as core::ops::drop::Drop>::drop () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#11 0x00007fb0be095d44 in core::ptr::drop_in_place$LT$bevy_ecs..storage..sparse_set..SparseSet$LT$bevy_ecs..component..ComponentId$C$bevy_ecs..storage..table..Column$GT$$GT$::h44420fa8e6f8f9e6 () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#12 0x00007fb0be096770 in core::ptr::drop_in_place$LT$bevy_ecs..archetype..Archetype$GT$::hb46f8d93949fb134 () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#13 0x00007fb0be085a78 in core::ptr::drop_in_place<bevy_app::app::App> () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#14 0x00007fb0be086c13 in <hashbrown::raw::RawTable<T,A> as core::ops::drop::Drop>::drop () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#15 0x00007fb0be099a66 in winit::platform_impl::platform::x11::EventLoop<T>::run_return () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#16 0x00007fb0be09c8bd in winit::platform_impl::platform::x11::EventLoop<T>::run () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#17 0x00007fb0be0c080a in winit::platform_impl::platform::EventLoop<T>::run () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#18 0x00007fb0be0b77ba in winit::event_loop::EventLoop<T>::run () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#19 0x00007fb0be0bebba in bevy_winit::run () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#20 0x00007fb0be0bf4c3 in bevy_winit::winit_runner_with () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#21 0x00007fb0be0b4b92 in core::ops::function::Fn::call () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#22 0x00007fb0bf30d55d in bevy_app::app::App::run () from /home/etam/code/codeberg/etam/rtcraft/target/release/deps/libbevy_dylib-a651404ea1914ff7.so
#23 0x000055a753cb8daf in rtcraft::main ()
#24 0x000055a753cb4c83 in std::sys_common::backtrace::__rust_begin_short_backtrace ()
#25 0x000055a753cbcee9 in std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h1ac2c171c485f843 ()
#26 0x00007fb0bd314bb1 in std::rt::lang_start_internal () from /usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-5c323425677a0310.so
#27 0x000055a753cb8e72 in main ()

@GiantBlargg
Copy link

GiantBlargg commented Jan 9, 2022

This is the same as #1908 and gfx-rs/wgpu#1446

@nicopap
Copy link
Contributor

nicopap commented Apr 3, 2023

This issue seems similar to #5524 and #1908, which are now fixed. I assume this is also fixed. If anyone can reproduce in bevy 0.10.0, please speak up.

It's probably a race condition, since it was "fixed" when pipelined rendering was introduced. But I simply can't reproduce while before it was fairly consistent, so I assume it's fully fixed 😛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Core Common functionality for all bevy apps C-Bug An unexpected or incorrect behavior O-Linux Specific to the Linux desktop operating system
Projects
None yet
Development

No branches or pull requests

6 participants