gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.69k stars 930 forks source link

Linux X11 Segfault on XCloseDisplay if PresentMode is Vsync #318

Open Friz64 opened 5 years ago

Friz64 commented 5 years ago

XCloseDisplay most of the time produces a segfault. This can be reproduced with the triangle example and with a personal test repo that's using wgpu-rs i set up. Changing PresentMode to NoVsync fixes the segfault. The segfault only happens on Intel/AMD Mesa and apparently not on Nvidia Proprietary.

One tester using the Nvidia Proprietary driver also experienced fluctuating FPS with my test repo. LOG: https://pastebin.com/raw/UzRqcPpz (note the first FPS print is inaccurate) (Unrelated)

Friz64 commented 5 years ago

maybe also related: https://github.com/cloudhead/rx/issues/1

Friz64 commented 5 years ago

I just locally ported the quad example from gfx master to glfw and reproduced the segfault issue. As expected only on PresentMode Fifo.

kvark commented 5 years ago

Could you post a stack trace from a debug build?

Friz64 commented 5 years ago

This backtrace is from my test repo

(gdb) backtrace
#0  unlink_chunk (p=p@entry=0x555555eac2f0, av=0x7ffff7e05c40 <main_arena>) at malloc.c:1469
#1  0x00007ffff7cb62c7 in _int_free (av=0x7ffff7e05c40 <main_arena>, p=0x555555eac2f0, have_lock=<optimized out>) at malloc.c:4341
#2  0x00007ffff7e856b0 in _XFreeDisplayStructure () from /lib/x86_64-linux-gnu/libX11.so.6
#3  0x00007ffff7e72c4f in XCloseDisplay () from /lib/x86_64-linux-gnu/libX11.so.6
#4  0x0000555555bf3b50 in _glfwPlatformTerminate ()
    at /home/friz64/.cargo/registry/src/github.com-1ecc6299db9ec823/glfw-sys-3.3.0/src/x11_init.c:1028
#5  0x0000555555bebdce in terminate () at /home/friz64/.cargo/registry/src/github.com-1ecc6299db9ec823/glfw-sys-3.3.0/src/init.c:91
#6  0x0000555555bec596 in glfwTerminate ()
    at /home/friz64/.cargo/registry/src/github.com-1ecc6299db9ec823/glfw-sys-3.3.0/src/init.c:272
#7  0x0000555555bc5a1d in glfw::init::glfw_terminate ()
    at /home/friz64/.cargo/registry/src/github.com-1ecc6299db9ec823/glfw-0.32.0/src/lib.rs:706
#8  0x00007ffff7c682ac in __run_exit_handlers (status=0, listp=0x7ffff7e05718 <__exit_funcs>, 
    run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:108
#9  0x00007ffff7c683da in __GI_exit (status=<optimized out>) at exit.c:139
#10 0x00007ffff7c47b72 in __libc_start_main (main=0x555555621550 <main>, argc=1, argv=0x7fffffffddd8, init=<optimized out>, 
    fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffddc8) at ../csu/libc-start.c:342
#11 0x000055555561b95a in _start ()
Friz64 commented 5 years ago

I have some great news on this! First off, this issue is not specific to GLFW as i have been able to also reproduce it with SDL2. Here's the actual issue and how to resolve it: https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/issues/1894 However i'm afraid i am not familiar enough with wgpu to implement this fix.

kvark commented 5 years ago

@Friz64 thank you! Sounds like it would go into gfx-backend-vulkan then under xlib feature.

cwfitzgerald commented 3 years ago

Going to close this as gfx has changed a lot since this issue. If it's still the case on wgpu master, feel free to re-open.

Friz64 commented 3 years ago

I don't remember the full ins and outs of this issue, but i think it's perfectly fine to close (especially because there have been no other reports on this in this issue). I just tried both the hello-triangle example and (quickly updated) GLFW code and both seem to work flawlessly!

Thank you for this maintenance work btw :+1:

radgeRayden commented 3 years ago

With a fresh build of wgpu-native's triangle example I can reproduce this segfault with the following call stack on Pop OS 21.04 (Ubuntu): https://gist.github.com/radgeRayden/b35e11873c5538ae0961206cad366634

Friz64 commented 3 years ago

I can reproduce it again (on wgpu-native's triangle example, like 20% of the time, Mesa/AMD on Arch Linux)! The call stack references line 267, which contains the call to glfwTerminate().


I'm pretty sure this same, or at least closely related, previously mentioned bug was also present in the Vulkan Cube Demos. The official fix looked like this: https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/commit/0017308648b6bf8eef10ef0ffb9470576c0c2e9e.

In the cube demos, destroy the instance after closing the display system connection. It is possible for the driver to register callback functions with a library like Xlib. If the driver is unloaded when Xlib calls those callback functions, a segfault results.

The bug is explained in more detail here in https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/issues/1894#issuecomment-309832783.

http://www.xfree86.org/4.7.0/DRI11.html suggests that the (GL, but Vulkan here) can register a callback with Xlib. When the application calls XCloseDisplay, this callback is called and will segfault if the driver had already been unloaded, which could happen when the Vulkan instance is destroyed. Fix is to destroy the instance after cleaning up the display connection.

So, without the fix, this happenend.

  1. vkDestroySurfaceKHR
  2. vkDestroyInstance -> Driver unloads and registered callback functions would now accesses freed memory (if i understand correctly?).
  3. glfwTerminate / XDestroyWindow -> Xlib calls the callback functions (if i understand correctly?).

The fix switches steps 2 and 3.


Now, the part i don't understand is... does the wgpu-native triangle example ever do something that causes the driver to unload? Nothing stands out to me. So is this even the same bug? Need some help here, not an expert on these things.

Another thing, regarding the present mode... still can only reproduce it with Fifo? This is something to consider too.

kvark commented 3 years ago

Filed https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/3262 to follow-up

kvark commented 3 years ago

The trail leads to https://gitlab.freedesktop.org/xorg/lib/libxext/-/issues/3

cubanismo commented 3 years ago

Note that's the only known issue when using current NV drivers. There may be other unrelated or related bugs in other drivers, or in older NV drivers, as it took a while for us to work all these teardown issues out of our stack.

robbert-vdh commented 2 years ago

Any updates on this? I too sometimes get segfaults when closing a window/application depending on the tide and the phase of the moon. I'm using wgpu in combination with iced and baseview (a windowing library specialized around embedding windows inside of other windows for plugin GUIs). Updating iced_baseview from the released iced version to the current master branch version solved the described issue for me with the included examples, but I'm still getting these same segfaults when closing my own embedded window in certain but not all hosts, and it also doesn't happen every time. I'm using wgpu 0.12.0 with the 510.54 NVIDIA drivers. Running the application under Carla, GDB now gives an even more useful backtrace (which is a good sign that there indeed is some nasty memory corruption going on somewhere):

GDB backtrace ``` Thread 1 "carla-bridge-na" received signal SIGSEGV, Segmentation fault. 0x000055555566fc4f in ?? () >>> bt #0 0x000055555566fc4f in () #1 0x00005555558187d8 in () #2 0x000055555582774b in () #3 0x0000555555828200 in () #4 0x000055555582ab9a in () #5 0x000055555582ad88 in () #6 0x00005555556fcfba in () #7 0x00005555556fd1c9 in () #8 0x000055555566c0fa in () #9 0x000055555566fba6 in () #10 0x00005555555a64a5 in () #11 0x0000555555680418 in () #12 0x00005555555a1941 in () #13 0x00005555555a1c05 in () #14 0x000055555559c70a in () #15 0x00007ffff7639310 in __libc_start_call_main () at /usr/lib/libc.so.6 #16 0x00007ffff76393c1 in __libc_start_main_impl () at /usr/lib/libc.so.6 #17 0x00005555555a11de in () ```

lldb usually gives a more normal backtrace pointing to XCloseDisplay:

lldb backtrace 1 ``` * thread #8, name = 'carla-bridge-na', stop reason = signal SIGSEGV: invalid address (fault address: 0x7ffff5038a90) * frame #0: 0x00007ffff5038a90 frame #1: 0x00007ffff7e47282 libX11.so.6`XCloseDisplay(dpy=0x00007fffd8000e70) at ClDisplay.c:65:8 frame #2: 0x00007fffefb55023 gain_gui.so`_$LT$xcb..base..Connection$u20$as$u20$core..ops..drop..Drop$GT$::drop::h0450333d0a5dbc55(self=0x00007fffedddcd50) at base.rs:722:17 frame #3: 0x00007fffefb5c6cb gain_gui.so`core::ptr::drop_in_place$LT$xcb..base..Connection$GT$::hd65771b77a683f13((null)=0x00007fffedddcd50) at mod.rs:188:1 frame #4: 0x00007fffef0cf757 gain_gui.so`core::ptr::drop_in_place$LT$baseview..x11..xcb_connection..XcbConnection$GT$::hc9eacf9c46cb7325((null)=0x00007fffedddcd50) at mod.rs:188:1 frame #5: 0x00007fffef0ce973 gain_gui.so`core::ptr::drop_in_place$LT$baseview..x11..window..Window$GT$::hb0d6403e351b5f81((null)=0x00007fffedddcd50) at mod.rs:188:1 frame #6: 0x00007fffef06a5ed gain_gui.so`baseview::x11::window::Window::window_thread::h33d98bfd2d9f7496(parent=Option @ 0x00007fffedddd0c8, options=WindowOpenOptions @ 0x00007fffedddd130, build={closure_env#0}, nih_plug::plugin::ParentWindowHandle> @ 0x00007fffedddd180, tx=SyncSender> @ 0x00007fffedddca00, parent_handle=Option @ 0x00007fffedddca08) at window.rs:366:5 frame #7: 0x00007fffef0695a4 gain_gui.so`baseview::x11::window::Window::open_parented::_$u7b$$u7b$closure$u7d$$u7d$::h800f850f972caae2 at window.rs:140:13 frame #8: 0x00007fffef0ac69f gain_gui.so`std::sys_common::backtrace::__rust_begin_short_backtrace::hf3330e074ec8b488(f=) at backtrace.rs:122:18 frame #9: 0x00007fffef0e0a23 gain_gui.so`std::thread::Builder::spawn_unchecked_::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h60fdd2053fa55682 at mod.rs:498:17 frame #10: 0x00007fffef052153 gain_gui.so`_$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::hefa6edf04bc74394(self=, _args=) at unwind_safe.rs:271:9 frame #11: 0x00007fffef0f58f0 gain_gui.so`std::panicking::try::do_call::h93bc275658bb6b2f(data="@v\xa4UUU") at panicking.rs:492:40 frame #12: 0x00007fffef0f5b4b gain_gui.so`__rust_try + 27 frame #13: 0x00007fffef0f5777 gain_gui.so`std::panicking::try::h9538b046b76ab660(f=) at panicking.rs:456:19 frame #14: 0x00007fffef068de3 gain_gui.so`std::panic::catch_unwind::hc4d556daffdeab72(f=) at panic.rs:137:14 frame #15: 0x00007fffef0e07ad gain_gui.so`std::thread::Builder::spawn_unchecked_::_$u7b$$u7b$closure$u7d$$u7d$::h683b6446cf71a870 at mod.rs:497:30 frame #16: 0x00007fffef0c7d4e gain_gui.so`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h0e28cb5679013b07((null)=0x00005555559a3100, (null)=) at function.rs:227:5 frame #17: 0x00007fffefbfa273 gain_gui.so`std::sys::unix::thread::Thread::new::thread_start::h32061b8c735ae2c0 [inlined] _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::h6d9707bce8e3821b at boxed.rs:1853:9 frame #18: 0x00007fffefbfa26d gain_gui.so`std::sys::unix::thread::Thread::new::thread_start::h32061b8c735ae2c0 [inlined] _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::h994cf8b5a1e078c4 at boxed.rs:1853:9 frame #19: 0x00007fffefbfa266 gain_gui.so`std::sys::unix::thread::Thread::new::thread_start::h32061b8c735ae2c0 at thread.rs:108:17 frame #20: 0x00007ffff76995c2 libc.so.6`start_thread + 722 frame #21: 0x00007ffff771e584 libc.so.6`__clone + 68 ```

But sometimes lldb points to vkDestroyInstance:

lldb backtrace 2 ``` * thread #8, name = 'carla-bridge-na', stop reason = signal SIGSEGV: invalid address (fault address: 0x10) * frame #0: 0x00007ffff769c8a4 libc.so.6`__pthread_mutex_lock@GLIBC_2.2.5 + 4 frame #1: 0x00007fff72a65649 libnvidia-glcore.so.510.54`___lldb_unnamed_symbol45327 + 185 frame #2: 0x00007fffae48c078 libGLX_nvidia.so.0`___lldb_unnamed_symbol3839 + 72 frame #3: 0x00007fffae4a4fef libGLX_nvidia.so.0`___lldb_unnamed_symbol4122 + 15 frame #4: 0x00007fffec138ee8 libvulkan.so.1`___lldb_unnamed_symbol1358 + 104 frame #5: 0x00007fffad2f2987 libVkLayer_khronos_validation.so`vulkan_layer_chassis::DestroyInstance(VkInstance_T*, VkAllocationCallbacks const*) at chassis.cpp:394:56 frame #6: 0x00007fffec149aed libvulkan.so.1`vkDestroyInstance + 221 frame #7: 0x00007fffef84ff7d gain_gui.so`ash::vk::features::InstanceFnV1_0::destroy_instance::h52aed89f6494c16c(self=0x00007fffd8694858, instance=Instance @ 0x00007fffeddda8a8, p_allocator=0x0000000000000000) at features.rs:545:9 frame #8: 0x00007fffef844cf8 gain_gui.so`ash::instance::Instance::destroy_instance::h1311525d62d50df5(self=0x00007fffd8694850, allocation_callbacks=Option<&ash::vk::definitions::AllocationCallbacks> @ 0x00007fffeddda8d8) at instance.rs:291:9 frame #9: 0x00007fffef6df501 gain_gui.so`wgpu_hal::vulkan::instance::_$LT$impl$u20$core..ops..drop..Drop$u20$for$u20$wgpu_hal..vulkan..InstanceShared$GT$::drop::hedae552619894d21(self=0x00007fffd8694850) at instance.rs:437:17 frame #10: 0x00007fffef707557 gain_gui.so`core::ptr::drop_in_place$LT$wgpu_hal..vulkan..InstanceShared$GT$::h8c7e23b62dc4b8b8((null)=0x00007fffd8694850) at mod.rs:188:1 frame #11: 0x00007fffef6f2b54 gain_gui.so`alloc::sync::Arc$LT$T$GT$::drop_slow::h31f244640546ec9e(self=0x00007fffd8b1eda8) at sync.rs:1092:18 frame #12: 0x00007fffef6f7973 gain_gui.so`_$LT$alloc..sync..Arc$LT$T$GT$$u20$as$u20$core..ops..drop..Drop$GT$::drop::h5dd94cdb5375526a(self=0x00007fffd8b1eda8) at sync.rs:1688:13 frame #13: 0x00007fffef708a7b gain_gui.so`core::ptr::drop_in_place$LT$alloc..sync..Arc$LT$wgpu_hal..vulkan..InstanceShared$GT$$GT$::h74c3223769ee0bb6((null)=0x00007fffd8b1eda8) at mod.rs:188:1 frame #14: 0x00007fffef5dd507 gain_gui.so`core::ptr::drop_in_place$LT$wgpu_hal..vulkan..Instance$GT$::h571a218e95ca52ee((null)=0x00007fffd8b1eda8) at mod.rs:188:1 frame #15: 0x00007fffef5de643 gain_gui.so`core::ptr::drop_in_place$LT$core..option..Option$LT$wgpu_hal..vulkan..Instance$GT$$GT$::h506344a4953dec89((null)=0x00007fffd8b1eda8) at mod.rs:188:1 frame #16: 0x00007fffef35feaf gain_gui.so`core::ptr::drop_in_place$LT$wgpu_core..instance..Instance$GT$::h83815661bb0d8360((null)=0x00007fffd8b1ed90) at mod.rs:188:1 frame #17: 0x00007fffef367fd7 gain_gui.so`core::ptr::drop_in_place$LT$wgpu_core..hub..Global$LT$wgpu_core..hub..IdentityManagerFactory$GT$$GT$::hff740f7c61806b1f((null)=0x00007fffd8b1ed90) at mod.rs:188:1 frame #18: 0x00007fffef360064 gain_gui.so`core::ptr::drop_in_place$LT$wgpu..backend..direct..Context$GT$::h9a55cd9bc1019bc5((null)=0x00007fffd8b1ed90) at mod.rs:188:1 frame #19: 0x00007fffef2d94a4 gain_gui.so`alloc::sync::Arc$LT$T$GT$::drop_slow::ha552dd328ac9c963(self=0x00007fffd9148e58) at sync.rs:1092:18 frame #20: 0x00007fffef2da4e3 gain_gui.so`_$LT$alloc..sync..Arc$LT$T$GT$$u20$as$u20$core..ops..drop..Drop$GT$::drop::h2ec4faecab86a4d5(self=0x00007fffd9148e58) at sync.rs:1688:13 frame #21: 0x00007fffef363d4b gain_gui.so`core::ptr::drop_in_place$LT$alloc..sync..Arc$LT$wgpu..backend..direct..Context$GT$$GT$::hd3628ecdcfd582a8((null)=0x00007fffd9148e58) at mod.rs:188:1 frame #22: 0x00007fffef35eea7 gain_gui.so`core::ptr::drop_in_place$LT$wgpu..Buffer$GT$::h75118f53f371a481((null)=0x00007fffd9148e58) at mod.rs:188:1 frame #23: 0x00007fffef35f7cb gain_gui.so`core::ptr::drop_in_place$LT$wgpu..util..belt..Chunk$GT$::h0f3c4be2697611c4((null)=0x00007fffd9148e58) at mod.rs:188:1 frame #24: 0x00007fffef357d6c gain_gui.so`core::ptr::drop_in_place$LT$wgpu..util..belt..StagingBelt..recall..$u7b$$u7b$closure$u7d$$u7d$..$u7b$$u7b$closure$u7d$$u7d$$GT$::h0580463129cda7bd at mod.rs:172:33 frame #25: 0x00007fffef35c60b gain_gui.so`core::ptr::drop_in_place$LT$core..future..from_generator..GenFuture$LT$wgpu..util..belt..StagingBelt..recall..$u7b$$u7b$closure$u7d$$u7d$..$u7b$$u7b$closure$u7d$$u7d$$GT$$GT$::h71049d5f9f314db9((null)=0x00007fffd9148e40) at mod.rs:188:1 frame #26: 0x00007fffef35cddb gain_gui.so`core::ptr::drop_in_place$LT$core..option..Option$LT$core..future..from_generator..GenFuture$LT$wgpu..util..belt..StagingBelt..recall..$u7b$$u7b$closure$u7d$$u7d$..$u7b$$u7b$closure$u7d$$u7d$$GT$$GT$$GT$::hf35216348ce6b009((null)=0x00007fffd9148e40) at mod.rs:188:1 frame #27: 0x00007fffef35cf64 gain_gui.so`core::ptr::drop_in_place$LT$$u5b$core..option..Option$LT$core..future..from_generator..GenFuture$LT$wgpu..util..belt..StagingBelt..recall..$u7b$$u7b$closure$u7d$$u7d$..$u7b$$u7b$closure$u7d$$u7d$$GT$$GT$$u5d$$GT$::h4e82434af377bc33((null)=*mut [core::option::Option>] @ 0x00007fffedddada8) at mod.rs:188:1 frame #28: 0x00007fffef2bd745 gain_gui.so`_$LT$alloc..vec..Vec$LT$T$C$A$GT$$u20$as$u20$core..ops..drop..Drop$GT$::drop::h66bae511efa4f136(self=0x00007fffd91d5ff0) at mod.rs:2821:13 frame #29: 0x00007fffef35d377 gain_gui.so`core::ptr::drop_in_place$LT$alloc..vec..Vec$LT$core..option..Option$LT$core..future..from_generator..GenFuture$LT$wgpu..util..belt..StagingBelt..recall..$u7b$$u7b$closure$u7d$$u7d$..$u7b$$u7b$closure$u7d$$u7d$$GT$$GT$$GT$$GT$::h1706e53e0fb5e399((null)=0x00007fffd91d5ff0) at mod.rs:188:1 frame #30: 0x00007fffef0cc3ab gain_gui.so`core::ptr::drop_in_place$LT$wgpu..util..belt..Join$LT$core..future..from_generator..GenFuture$LT$wgpu..util..belt..StagingBelt..recall..$u7b$$u7b$closure$u7d$$u7d$..$u7b$$u7b$closure$u7d$$u7d$$GT$$GT$$GT$::hc0a36c8cfd485316((null)=0x00007fffd91d5ff0) at mod.rs:188:1 frame #31: 0x00007fffef0cca36 gain_gui.so`core::ptr::drop_in_place$LT$alloc..boxed..Box$LT$wgpu..util..belt..Join$LT$core..future..from_generator..GenFuture$LT$wgpu..util..belt..StagingBelt..recall..$u7b$$u7b$closure$u7d$$u7d$..$u7b$$u7b$closure$u7d$$u7d$$GT$$GT$$GT$$GT$::h227603f194673616((null)=0x00007fffedddae70) at mod.rs:188:1 frame #32: 0x00007fffef02c9cd gain_gui.so`core::mem::drop::h966c55fd23d238bb(_x=0x00007fffd91d5ff0) at mod.rs:965:24 frame #33: 0x00007fffef0990c6 gain_gui.so`futures_task::future_obj::if_alloc::_$LT$impl$u20$futures_task..future_obj..UnsafeFutureObj$LT$T$GT$$u20$for$u20$alloc..boxed..Box$LT$F$GT$$GT$::drop::h9641156539c8ecf4(ptr=*mut dyn core::future::future::Future, Output=()> @ 0x00007fffedddae98) at future_obj.rs:227:13 frame #34: 0x00007fffefb3abb5 gain_gui.so`_$LT$futures_task..future_obj..LocalFutureObj$LT$T$GT$$u20$as$u20$core..ops..drop..Drop$GT$::drop::h7720f885776cde38(self=0x00007fffd936bdf0) at future_obj.rs:90:18 frame #35: 0x00007fffefb3ba8b gain_gui.so`core::ptr::drop_in_place$LT$futures_task..future_obj..LocalFutureObj$LT$$LP$$RP$$GT$$GT$::h9967718bd0dc520b((null)=0x00007fffd936bdf0) at mod.rs:188:1 frame #36: 0x00007fffefb3b974 gain_gui.so`core::ptr::drop_in_place$LT$core..option..Option$LT$futures_task..future_obj..LocalFutureObj$LT$$LP$$RP$$GT$$GT$$GT$::h81895314fc9bc672((null)=0x00007fffd936bdf0) at mod.rs:188:1 frame #37: 0x00007fffefb0b6ed gain_gui.so`futures_util::stream::futures_unordered::FuturesUnordered$LT$Fut$GT$::release_task::hd603dd2d77fca6ae(self=0x00007fffd925cd70, task=strong=1, weak=0) at mod.rs:262:13 frame #38: 0x00007fffefb0b879 gain_gui.so`futures_util::stream::futures_unordered::FuturesUnordered$LT$Fut$GT$::clear_head_all::h747c955232306660(self=0x00007fffd925cd70) at mod.rs:569:13 frame #39: 0x00007fffefb0a96b gain_gui.so`_$LT$futures_util..stream..futures_unordered..FuturesUnordered$LT$Fut$GT$$u20$as$u20$core..ops..drop..Drop$GT$::drop::h38316c38d1eb8a26(self=0x00007fffd925cd70) at mod.rs:580:9 frame #40: 0x00007fffefb08747 gain_gui.so`core::ptr::drop_in_place$LT$futures_util..stream..futures_unordered..FuturesUnordered$LT$futures_task..future_obj..LocalFutureObj$LT$$LP$$RP$$GT$$GT$$GT$::h95f032d5fc9111f3((null)=0x00007fffd925cd70) at mod.rs:188:1 frame #41: 0x00007fffef0cf337 gain_gui.so`core::ptr::drop_in_place$LT$futures_executor..local_pool..LocalPool$GT$::hccea8648d1c065a1((null)=0x00007fffd925cd70) at mod.rs:188:1 frame #42: 0x00007fffef0cf548 gain_gui.so`core::ptr::drop_in_place$LT$iced_wgpu..window..compositor..Compositor$GT$::hcabc55a4ebadbc63((null)=0x00007fffd925cca8) at mod.rs:188:1 frame #43: 0x00007fffef053f27 gain_gui.so`iced_baseview::window::run_instance::_$u7b$$u7b$closure$u7d$$u7d$::ha41fa0be45fa7ba4((null)=ResumeTy @ 0x00007fffedddc1c0) at window.rs:560:1 frame #44: 0x00007fffef078859 gain_gui.so`_$LT$core..future..from_generator..GenFuture$LT$T$GT$$u20$as$u20$core..future..future..Future$GT$::poll::hb9162c15a8483318(self=Pin<&mut core::future::from_generator::GenFuture, futures_executor::thread_pool::ThreadPool>>> @ 0x00007fffedddc458, cx=0x00007fffedddcf08) at mod.rs:91:19 frame #45: 0x00007fffef057392 gain_gui.so`_$LT$iced_baseview..window..IcedWindow$LT$A$GT$$u20$as$u20$baseview..window..WindowHandler$GT$::on_event::h0dbbf159f950f607(self=0x00007fffedddcef0, window=0x00007fffedddc6f0, event=Event @ 0x00007fffedddc6f8) at window.rs:502:21 frame #46: 0x00007fffefb4224a gain_gui.so`baseview::x11::window::Window::handle_must_close::h3040a0da1b80bf98(self=0x00007fffedddcd50, handler=&mut dyn baseview::window::WindowHandler @ 0x00007fffedddc768) at window.rs:510:9 frame #47: 0x00007fffefb42107 gain_gui.so`baseview::x11::window::Window::run_event_loop::hb586b7f8d1ed2c4f(self=0x00007fffedddcd50, handler=&mut dyn baseview::window::WindowHandler @ 0x00007fffedddc878) at window.rs:489:21 frame #48: 0x00007fffef06a5b6 gain_gui.so`baseview::x11::window::Window::window_thread::h33d98bfd2d9f7496(parent=Option @ 0x00007fffedddd0c8, options=WindowOpenOptions @ 0x00007fffedddd130, build={closure_env#0}, nih_plug::plugin::ParentWindowHandle> @ 0x00007fffedddd180, tx=SyncSender> @ 0x00007fffedddca00, parent_handle=Option @ 0x00007fffedddca08) at window.rs:365:9 frame #49: 0x00007fffef0695a4 gain_gui.so`baseview::x11::window::Window::open_parented::_$u7b$$u7b$closure$u7d$$u7d$::h800f850f972caae2 at window.rs:140:13 frame #50: 0x00007fffef0ac69f gain_gui.so`std::sys_common::backtrace::__rust_begin_short_backtrace::hf3330e074ec8b488(f=) at backtrace.rs:122:18 frame #51: 0x00007fffef0e0a23 gain_gui.so`std::thread::Builder::spawn_unchecked_::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h60fdd2053fa55682 at mod.rs:498:17 frame #52: 0x00007fffef052153 gain_gui.so`_$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::hefa6edf04bc74394(self=, _args=) at unwind_safe.rs:271:9 frame #53: 0x00007fffef0f58f0 gain_gui.so`std::panicking::try::do_call::h93bc275658bb6b2f(data="\U00000010v\xa4UUU") at panicking.rs:492:40 frame #54: 0x00007fffef0f5b4b gain_gui.so`__rust_try + 27 frame #55: 0x00007fffef0f5777 gain_gui.so`std::panicking::try::h9538b046b76ab660(f=) at panicking.rs:456:19 frame #56: 0x00007fffef068de3 gain_gui.so`std::panic::catch_unwind::hc4d556daffdeab72(f=) at panic.rs:137:14 frame #57: 0x00007fffef0e07ad gain_gui.so`std::thread::Builder::spawn_unchecked_::_$u7b$$u7b$closure$u7d$$u7d$::h683b6446cf71a870 at mod.rs:497:30 frame #58: 0x00007fffef0c7d4e gain_gui.so`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h0e28cb5679013b07((null)=0x00005555559ac030, (null)=) at function.rs:227:5 frame #59: 0x00007fffefbfa273 gain_gui.so`std::sys::unix::thread::Thread::new::thread_start::h32061b8c735ae2c0 [inlined] _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::h6d9707bce8e3821b at boxed.rs:1853:9 frame #60: 0x00007fffefbfa26d gain_gui.so`std::sys::unix::thread::Thread::new::thread_start::h32061b8c735ae2c0 [inlined] _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::h994cf8b5a1e078c4 at boxed.rs:1853:9 frame #61: 0x00007fffefbfa266 gain_gui.so`std::sys::unix::thread::Thread::new::thread_start::h32061b8c735ae2c0 at thread.rs:108:17 frame #62: 0x00007ffff76995c2 libc.so.6`start_thread + 722 frame #63: 0x00007ffff771e584 libc.so.6`__clone + 68 ```

I'm not really sure where to go from here.

robbert-vdh commented 1 year ago

As yet another data point, leaking the Surface (so drop() never gets called) also works around the segfault. Not an actual solution of course, but it may help track down the issue. Also, in combination with baseview, it only seems to happen when using RawWindowHandle::Xlib/RawDisplayHandle::Xlib. Changing the HasRawWindowHandle/HasRawDisplayHandle instances to use RawWindowHandle::Xcb/RawDisplayHandle::Xcb instead seems to get rid of these segfaults.

edwardgallyot commented 7 months ago

I can confirm that I am also seeing this issue whilst using baseview with 535 Nvidia and wgpu 0.18