Segmentation fault in radeon driver/mesa when using sidebars
Describe the bug
I have somehow managed to trigger a segmentation fault inside mesa when using egui on my radeon GPU.
Here is a backtrace and thread list from gdb when running `cargo build --release && gdb ./target/release/
>>> back
#0 dri_is_thread_safe () at ../mesa-22.3.2/src/egl/drivers/dri2/egl_dri2.c:164
#1 0x00007ffff52afef3 in dri_create_context () at ../mesa-22.3.2/src/gallium/frontends/dri/dri_context.c:220
#2 0x00007ffff52b35de in driCreateContextAttribs () at ../mesa-22.3.2/src/gallium/frontends/dri/dri_util.c:642
#3 0x00007ffff52b3772 in driCreateNewContextForAPI () at ../mesa-22.3.2/src/gallium/frontends/dri/dri_util.c:659
#4 driCreateNewContext () at ../mesa-22.3.2/src/gallium/frontends/dri/dri_util.c:667
#5 0x00007ffff75aa034 in loader_dri3_blit_context_get () at ../mesa-22.3.2/src/loader/loader_dri3_helper.c:173
#6 loader_dri3_blit_image () at ../mesa-22.3.2/src/loader/loader_dri3_helper.c:222
#7 loader_dri3_blit_image () at ../mesa-22.3.2/src/loader/loader_dri3_helper.c:208
#8 0x00007ffff75ac412 in dri3_get_buffer () at ../mesa-22.3.2/src/loader/loader_dri3_helper.c:2098
#9 0x00007ffff75ac7bb in loader_dri3_get_buffers () at ../mesa-22.3.2/src/loader/loader_dri3_helper.c:2287
#10 0x00007ffff52ad41a in dri_image_drawable_get_buffers () at ../mesa-22.3.2/src/gallium/frontends/dri/dri2.c:290
#11 0x00007ffff52ad5b1 in dri2_allocate_textures () at ../mesa-22.3.2/src/gallium/frontends/dri/dri2.c:465
#12 0x00007ffff52b0685 in dri_st_framebuffer_validate () at ../mesa-22.3.2/src/gallium/frontends/dri/dri_drawable.c:82
#13 0x00007ffff5377eca in st_framebuffer_validate () at ../mesa-22.3.2/src/mesa/state_tracker/st_manager.c:236
#14 0x00007ffff5378a56 in st_manager_validate_framebuffers () at ../mesa-22.3.2/src/mesa/state_tracker/st_manager.c:1340
#15 0x00007ffff5352306 in st_validate_state () at ../mesa-22.3.2/src/mesa/state_tracker/st_atom.c:231
#16 0x00007ffff5540aca in st_Clear () at ../mesa-22.3.2/src/mesa/state_tracker/st_cb_clear.c:432
#17 0x00007ffff5565878 in _mesa_unmarshal_Clear () at src/mapi/glapi/gen/marshal_generated1.c:206
#18 0x00007ffff54d9ec8 in glthread_unmarshal_batch () at ../mesa-22.3.2/src/mesa/main/glthread.c:65
#19 0x00007ffff52bc966 in util_queue_thread_func () at ../mesa-22.3.2/src/util/u_queue.c:309
#20 0x00007ffff530c43c in impl_thrd_routine () at ../mesa-22.3.2/src/c11/impl/threads_posix.c:67
#21 0x00007ffff7be88fd in start_thread (arg=<optimized out>) at pthread_create.c:442
#22 0x00007ffff7c6aa60 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
>>> info threads
Id Target Id Frame
1 Thread 0x7ffff77b2ac0 (LWP 50484) "waveview" syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
2 Thread 0x7fffeb9ff6c0 (LWP 50490) "waveview:cs0" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555ced6fc) at futex-internal.c:57
3 Thread 0x7fffeb1fe6c0 (LWP 50491) "wavevie:disk$0" __GI___fstatat64 (fd=fd@entry=11, file=file@entry=0x7ffff7cf9dd5 "", buf=buf@entry=0x7fffeb1fd7f0, flag=flag@entry=4096) at ../sysdeps/unix/sysv/linux/fstatat64.c:167
4 Thread 0x7fffea9fd6c0 (LWP 50492) "waveview:sh0" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555ceb604) at futex-internal.c:57
5 Thread 0x7fffea1fc6c0 (LWP 50493) "waveview:shlo0" llvm::Use::get () at /usr/src/debug/llvm/llvm-14.0.6.src/include/llvm/IR/Use.h:66
6 Thread 0x7fffe95fb6c0 (LWP 50494) "waveview:gdrv0" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x555555e18b40) at futex-internal.c:57
* 7 Thread 0x7fffe8dfa6c0 (LWP 50495) "waveview:gl0" dri_is_thread_safe () at ../mesa-22.3.2/src/egl/drivers/dri2/egl_dri2.c:164
8 Thread 0x7fffe83f96c0 (LWP 50496) "waveview" 0x00007ffff7c5d0bf in __GI___poll (fds=0x7fffe83f8670, nfds=1, timeout=-1) at ../sysdeps/unix/sysv/linux/poll.c:29
9 Thread 0x7fffca9fb6c0 (LWP 50497) "wavevie:disk$1" __GI___open64_nocancel (file=0x7fffc4008d80 "/home/frans/.cache/mesa_shader_cache/a2", oflag=oflag@entry=591872) at ../sysdeps/unix/sysv/linux/open64_nocancel.c:39
10 Thread 0x7fffc99f96c0 (LWP 50498) "wavevie:disk$2" __GI___getdents64 (fd=12, buf=buf@entry=0x7fffbc008de0, nbytes=<optimized out>) at ../sysdeps/unix/sysv/linux/getdents64.c:32
11 Thread 0x7fffcb1fc6c0 (LWP 50499) "waveview:gdrv0" __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x7fffcc060f80) at futex-internal.c:57
And a backtrace of thread 1:
>>> thread 1
[Switching to thread 1 (Thread 0x7ffff77b2ac0 (LWP 50484))]
#0 syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
38 cmpq $-4095, %rax /* Check %rax for error. */
>>> back
#0 syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
#1 0x00007ffff52b7057 in sys_futex () at ../mesa-22.3.2/src/util/futex.c:43
#2 futex_wait () at ../mesa-22.3.2/src/util/futex.c:55
#3 0x00007ffff52bc670 in do_futex_fence_wait () at ../mesa-22.3.2/src/util/u_queue.c:130
#4 0x00007ffff54da2e0 in util_queue_fence_wait () at ../mesa-22.3.2/src/util/u_queue.h:163
#5 _mesa_glthread_finish () at ../mesa-22.3.2/src/mesa/main/glthread.c:292
#6 _mesa_glthread_finish () at ../mesa-22.3.2/src/mesa/main/glthread.c:273
#7 0x00007ffff52b0df5 in dri_flush () at ../mesa-22.3.2/src/gallium/frontends/dri/dri_drawable.c:485
#8 0x00007ffff75ab7a2 in loader_dri3_swap_buffers_msc () at ../mesa-22.3.2/src/loader/loader_dri3_helper.c:1017
#9 0x00007ffff75a26c0 in dri3_swap_buffers_with_damage () at ../mesa-22.3.2/src/egl/drivers/dri2/platform_x11_dri3.c:447
#10 dri3_swap_buffers () at ../mesa-22.3.2/src/egl/drivers/dri2/platform_x11_dri3.c:456
#11 0x00007ffff759b8e8 in dri2_swap_buffers () at ../mesa-22.3.2/src/egl/drivers/dri2/egl_dri2.c:2052
#12 0x00007ffff758fae5 in eglSwapBuffers () at ../mesa-22.3.2/src/egl/main/eglapi.c:1468
#13 0x00005555555ec4b5 in glutin_egl_sys::egl::Egl::SwapBuffers () at /home/frans/Documents/rust/egui_segfault/target/release/build/glutin_egl_sys-d91a67295b34b226/out/egl_bindings.rs:587
#14 glutin::api::egl::surface::{impl#3}::swap_buffers<glutin::surface::WindowSurface> (self=0x7fffffffc4d0, context=<optimized out>) at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/glutin-0.30.3/src/api/egl/surface.rs:338
#15 glutin::surface::{impl#11}::swap_buffers<glutin::surface::WindowSurface> (self=0x7fffffffc4d0, context=<optimized out>) at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/glutin-0.30.3/src/surface.rs:302
#16 0x000055555561cc06 in eframe::native::run::glow_integration::GlutinWindowContext::swap_buffers (self=0x7fffffffc428) at src/native/run.rs:465
#17 eframe::native::run::glow_integration::{impl#2}::paint (self=0x7fffffffc010) at src/native/run.rs:683
#18 0x00005555555d98a0 in eframe::native::run::run_and_return::{closure#0}<eframe::native::run::glow_integration::GlowWinitApp> (event=..., event_loop=<optimized out>, control_flow=0x7fffffffb2a0) at src/native/run.rs:135
#19 0x0000555555628f34 in winit::platform_impl::platform::sticky_exit_callback<eframe::native::run::UserEvent, eframe::native::run::run_and_return::{closure_env#0}<eframe::native::run::glow_integration::GlowWinitApp>> (evt=..., target=0x2, control_flow=0x7fffffffb2a0, callback=0x7fffffffb930) at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/mod.rs:849
#20 winit::platform_impl::platform::x11::{impl#2}::run_return::single_iteration<eframe::native::run::UserEvent, eframe::native::run::run_and_return::{closure_env#0}<eframe::native::run::glow_integration::GlowWinitApp>> (this=<optimized out>, control_flow=0x7fffffffb2a0, cause=0x7fffffffb310, callback=0x7fffffffb930) at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/x11/mod.rs:380
#21 0x0000555555629cf0 in winit::platform_impl::platform::x11::EventLoop<eframe::native::run::UserEvent>::run_return<eframe::native::run::UserEvent, eframe::native::run::run_and_return::{closure_env#0}<eframe::native::run::glow_integration::GlowWinitApp>> (self=0x7ffff77b2748, callback=...) at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/x11/mod.rs:488
#22 0x000055555562cb55 in winit::platform_impl::platform::EventLoop<eframe::native::run::UserEvent>::run_return<eframe::native::run::UserEvent, eframe::native::run::run_and_return::{closure_env#0}<eframe::native::run::glow_integration::GlowWinitApp>> (self=0x7ffff77b2748, callback=...) at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/mod.rs:748
#23 winit::platform::run_return::{impl#0}::run_return<eframe::native::run::UserEvent, eframe::native::run::run_and_return::{closure_env#0}<eframe::native::run::glow_integration::GlowWinitApp>> (self=0x7ffff77b2748, event_handler=...) at /home/frans/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform/run_return.rs:62
#24 eframe::native::run::run_and_return<eframe::native::run::glow_integration::GlowWinitApp> (event_loop=0x7ffff77b2748, winit_app=...) at src/native/run.rs:115
#25 0x00005555555eabfd in eframe::native::run::glow_integration::run_glow::{closure#0} (event_loop=0x7ffff77b2748, native_options=...) at src/native/run.rs:873
#26 eframe::native::run::with_event_loop::{closure#0}<core::result::Result<(), eframe::Error>, eframe::native::run::glow_integration::run_glow::{closure_env#0}> (event_loop=...) at src/native/run.rs:99
#27 std::thread::local::LocalKey<core::cell::RefCell<core::option::Option<winit::event_loop::EventLoop<eframe::native::run::UserEvent>>>>::try_with<core::cell::RefCell<core::option::Option<winit::event_loop::EventLoop<eframe::native::run::UserEvent>>>, eframe::native::run::with_event_loop::{closure_env#0}<core::result::Result<(), eframe::Error>, eframe::native::run::glow_integration::run_glow::{closure_env#0}>, core::result::Result<(), eframe::Error>> (f=..., self=<optimized out>) at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/thread/local.rs:446
#28 std::thread::local::LocalKey<core::cell::RefCell<core::option::Option<winit::event_loop::EventLoop<eframe::native::run::UserEvent>>>>::with<core::cell::RefCell<core::option::Option<winit::event_loop::EventLoop<eframe::native::run::UserEvent>>>, eframe::native::run::with_event_loop::{closure_env#0}<core::result::Result<(), eframe::Error>, eframe::native::run::glow_integration::run_glow::{closure_env#0}>, core::result::Result<(), eframe::Error>> (self=<optimized out>, f=...) at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/thread/local.rs:422
#29 0x000055555561fc0b in eframe::native::run::with_event_loop<core::result::Result<(), eframe::Error>, eframe::native::run::glow_integration::run_glow::{closure_env#0}> (f=..., native_options=<error reading variable: Cannot access memory at address 0x0>) at src/native/run.rs:92
#30 eframe::native::run::glow_integration::run_glow (app_name=..., native_options=..., app_creator=...) at src/native/run.rs:866
#31 eframe::run_native (app_name=..., native_options=..., app_creator=...) at src/lib.rs:199
#32 0x00005555555b9f9c in waveview::main () at src/main.rs:10
This seems to happen at the 4th rendered frame based on my printf debugging
To Reproduce
This does not happen on my intel gpu based laptop, but does happen on my desktop with an rx 6800 running a fresh arch installation with mesa 22.3.2-1
I have a minimal reproduction here https://gitlab.com/TheZoq2/egui-segfault, running cargo run --release triggers it consistently with the following output:
Update
Drawing left panel
Drawing signal list
Drawing signals
Processing messages
Update
Drawing left panel
Drawing signal list
Drawing signals
Processing messages
Update
Drawing left panel
Drawing signal list
Drawing signals
Processing messages
i.e., it seems to render 3 frames
When running in gdb, it freezes in this state:

Outside gdb, it quickly displays a correct view beore crashing
Desktop: Up-to-date Arch linux with a ryzen 7 3800x and an rx6800 gpu. Runnig eframe native
Additional context I presume this might be a downstream problem, but I don't know enough about egui, eframe or the native rendering to test further
Found another interesting observation:
Changing the opt-level of debug mode to O3 does not yield a segfault, and it keeps segfaulting in release mode, even at opt level 0
It also seems to depend quite a bit on resizing. The particular reproduction does not, but with some changes, it can work until I resize the window.
Does the segfault go away if you disable vsync?
let options = eframe::NativeOptions {
initial_window_size: Some(egui::vec2(320.0, 240.0)),
vsync: false,
..Default::default()
};
This looks like an issue with either glutin or egl. There is clearly unsafe code on the call stack, e.g., https://github.com/rust-windowing/glutin/blob/v0.30.3/glutin/src/api/egl/surface.rs#L338 -- and no comment describing why it is safe to do this or what invariants need to be upheld.
Seems to still segfault with vsync off
I can confirm I have the same (or very similar issue) with my Vega 56 on Fedora 37. Resizing in release mode causes a segmentation fault, but debug mode is fine.