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

bug: Segmentation fault while closing window #347

Open
katyo opened this issue Oct 21, 2023 · 11 comments
Open

bug: Segmentation fault while closing window #347

katyo opened this issue Oct 21, 2023 · 11 comments
Assignees
Labels

Comments

@katyo
Copy link
Contributor

katyo commented Oct 21, 2023

When I try to close window by click (x) button I have a segmentation fault.

GDB shows the following backtrace:

Thread 1 "ex1" received signal SIGSEGV, Segmentation fault.
0x00007ffff5c8c904 in dri3_wait_for_event_locked () from /run/opengl-driver/lib/libGLX_mesa.so.0
(gdb) backtrace
#0  0x00007ffff5c8c904 in dri3_wait_for_event_locked () from /run/opengl-driver/lib/libGLX_mesa.so.0
#1  0x00007ffff5c8e97a in loader_dri3_swapbuffer_barrier () from /run/opengl-driver/lib/libGLX_mesa.so.0
#2  0x00007fffce0b3dc6 in dri_st_framebuffer_flush_swapbuffers () from /run/opengl-driver/lib/dri/radeonsi_dri.so
#3  0x00007fffce15cf7c in st_finish () from /run/opengl-driver/lib/dri/radeonsi_dri.so
#4  0x00007fffce15cff0 in st_glFinish () from /run/opengl-driver/lib/dri/radeonsi_dri.so
#5  0x0000555556893fe6 in GrGLFunction<void ()>::GrGLFunction(void (*)())::{lambda(void const*)#1}::operator()(void const*) const ()
#6  0x0000555556893fc5 in GrGLFunction<void ()>::GrGLFunction(void (*)())::{lambda(void const*)#1}::__invoke(void const*) ()
#7  0x00005555561885ce in GrGLFunction<void ()>::operator()() const ()
#8  0x000055555619b0a6 in GrGLGpu::finishOutstandingGpuWork() ()
#9  0x0000555555fbc7fd in GrDirectContext::syncAllOutstandingGpuWork(bool) ()
#10 0x0000555555fbc598 in GrDirectContext::~GrDirectContext() ()
#11 0x0000555555fbcc7c in GrDirectContext::~GrDirectContext() ()
#12 0x0000555555c9122b in SkRefCntBase::internal_dispose() const ()
#13 0x0000555555c94029 in SkRefCntBase::unref() const ()
#14 0x000055555641b395 in C_SkRefCntBase_unref (self=0x555558a1b4a0) at src/bindings.cpp:1699
#15 0x0000555555a7d84b in skia_safe::prelude::{impl#8}::_unref (self=0x555558a1b4a0) at src/prelude.rs:142
#16 0x00005555557d0c24 in skia_safe::prelude::{impl#9}::_unref<skia_bindings::GrDirectContext, skia_bindings::SkRefCntBase> (self=0x555558a1b4a0)
    at /home/kayo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/skia-safe-0.66.3/src/prelude.rs:182
#17 0x000055555578d141 in skia_safe::prelude::{impl#32}::drop<skia_bindings::GrDirectContext> (self=0x7fffffff5048)
    at /home/kayo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/skia-safe-0.66.3/src/prelude.rs:632
#18 0x000055555579b23b in core::ptr::drop_in_place<skia_safe::prelude::RCHandle<skia_bindings::GrDirectContext>> ()
    at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ptr/mod.rs:497
#19 0x000055555579a25a in core::ptr::drop_in_place<freya_renderer::window::WindowEnv<()>> ()
    at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ptr/mod.rs:497
#20 0x00005555557997da in core::ptr::drop_in_place<freya_renderer::app::App<()>> ()
    at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ptr/mod.rs:497
#21 0x00005555557948bf in core::ptr::drop_in_place<freya_renderer::event_loop::run_event_loop::{closure_env#0}<()>> ()
    at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ptr/mod.rs:497
#22 0x000055555575831a in winit::platform_impl::platform::x11::EventLoop<freya_common::event_messages::EventMessage>::run_return<freya_common::event_messages::EventMessage, freya_renderer::event_loop::run_event_loop::{closure_env#0}<()>> (self=0x7fffffff44d0, callback=...)
    at /home/kayo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.28.7/src/platform_impl/linux/x11/mod.rs:492
#23 0x000055555575ab61 in winit::platform_impl::platform::x11::EventLoop<freya_common::event_messages::EventMessage>::run<freya_common::event_messages::EventMessage, freya_renderer::event_loop::run_event_loop::{closure_env#0}<()>> (self=..., callback=<error reading variable: Cannot access memory at address 0x0>)
    at /home/kayo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.28.7/src/platform_impl/linux/x11/mod.rs:498
#24 0x00005555557195e5 in winit::platform_impl::platform::EventLoop<freya_common::event_messages::EventMessage>::run<freya_common::event_messages::EventMessage, freya_renderer::event_loop::run_event_loop::{closure_env#0}<()>> (self=..., callback=...)
    at /home/kayo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.28.7/src/platform_impl/linux/mod.rs:792
#25 0x00005555557a0f1d in winit::event_loop::EventLoop<freya_common::event_messages::EventMessage>::run<freya_common::event_messages::EventMessage, freya_renderer::event_loop::run_event_loop::{closure_env#0}<()>> (self=..., event_handler=...)
    at /home/kayo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.28.7/src/event_loop.rs:305
#26 0x00005555557aff1e in freya_renderer::event_loop::run_event_loop<()> (app=..., event_loop=..., proxy=..., hovered_node=...)
    at /home/kayo/.cargo/git/checkouts/freya-aa88117f1f713ee2/6dda57e/crates/renderer/src/event_loop.rs:38
#27 0x0000555555741f0a in freya_renderer::run_app<()> (vdom=..., rdom=..., config=..., mutations_notifier=..., hovered_node=...)
    at /home/kayo/.cargo/git/checkouts/freya-aa88117f1f713ee2/6dda57e/crates/renderer/src/lib.rs:64
#28 0x0000555555720028 in freya::launch::launch_cfg<()> (app=0x555555709790 <ex1::app>, config=...) at src/launch.rs:214
#29 0x000055555571fd2b in freya::launch::launch (app=0x555555709790 <ex1::app>) at src/launch.rs:33
#30 0x000055555570978e in ex1::main () at src/main.rs:9

Seems something wrong with finalizing.

$ cat /etc/os-release
BUG_REPORT_URL="https://github.com/NixOS/nixpkgs/issues"
BUILD_ID="23.05.3242.da5adce0ffaf"
DOCUMENTATION_URL="https://nixos.org/learn.html"
HOME_URL="https://nixos.org/"
ID=nixos
LOGO="nix-snowflake"
NAME=NixOS
PRETTY_NAME="NixOS 23.05 (Stoat)"
SUPPORT_END="2023-12-31"
SUPPORT_URL="https://nixos.org/community.html"
VERSION="23.05 (Stoat)"
VERSION_CODENAME=stoat
VERSION_ID="23.05"

$ uname -a
Linux nixie-workhorse 6.5.1 #1-NixOS SMP PREEMPT_DYNAMIC Sat Sep  2 07:13:30 UTC 2023 x86_64 GNU/Linux

$ glxinfo | grep "renderer "
Extended renderer info (GLX_MESA_query_renderer):
OpenGL renderer string: AMD Radeon Graphics (renoir, LLVM 15.0.7, DRM 3.54, 6.5.1)
@marc2332 marc2332 added the bug 😔 Something isn't working label Oct 21, 2023
@marc2332
Copy link
Owner

Hey! What Linux distribution do you use?

@katyo
Copy link
Contributor Author

katyo commented Oct 21, 2023

NixOS 23.05

@marc2332
Copy link
Owner

marc2332 commented Oct 21, 2023

NixOS 23.05

I am not very familiar with NixOS but looks like the error is coming from Skia (the renderer that Freya uses). I wonder if NixOS might have something disabled and that made it crash... I have never experienced this in other distros, I'll open an issue asap in rust-skia to see if they can help ✌️

@katyo
Copy link
Contributor Author

katyo commented Oct 21, 2023

@marc2332 Thanks! Also I have added some info about my env and hw.

@marc2332
Copy link
Owner

Thanks! I appreciate that 😄

@tronical
Copy link

I don’t know if this helps much, but there are two things I’ve learned while using skia in Slint with GL:

(1) we call flush() in the context before swapping Gl buffers
(2) before dropping the context, make sure the GL context is current. If that fails (for some reason), call abandon().

Your stack trace shows that Skia wants to call glFinish in the destructor - that doesn’t seem like a great idea. I think ideally it would be merely glDeleteXxx calls to free various GPU buffers and handles.

@marc2332
Copy link
Owner

I don’t know if this helps much, but there are two things I’ve learned while using skia in Slint with GL:

(1) we call flush() in the context before swapping Gl buffers (2) before dropping the context, make sure the GL context is current. If that fails (for some reason), call abandon().

Your stack trace shows that Skia wants to call glFinish in the destructor - that doesn’t seem like a great idea. I think ideally it would be merely glDeleteXxx calls to free various GPU buffers and handles.

Hey Simon! Thanks for the tips!

  1. Yes, I am already doing that ✅
  2. Just opened fix: Abandon context if not current when closing the app #355, is that what you meant?

Thanks! 😄 ✌️

@katyo
Copy link
Contributor Author

katyo commented Oct 23, 2023

By the way, I tested #355, but it doesn't solve the problem with segfault for me.

@tronical
Copy link

I don’t know if this helps much, but there are two things I’ve learned while using skia in Slint with GL:
(1) we call flush() in the context before swapping Gl buffers (2) before dropping the context, make sure the GL context is current. If that fails (for some reason), call abandon().
Your stack trace shows that Skia wants to call glFinish in the destructor - that doesn’t seem like a great idea. I think ideally it would be merely glDeleteXxx calls to free various GPU buffers and handles.

Hey Simon! Thanks for the tips!

  1. Yes, I am already doing that ✅
  2. Just opened fix: Abandon context if not current when closing the app #355, is that what you meant?

Yes, almost: I think instead of just checking I suggest to also make the context current.

I see another issue though: The order of fields also affects how the different Drop implementations / destructors are called. Right now I see:

    surface: Surface,
    gl_surface: GlutinSurface<WindowSurface>,
    gr_context: DirectContext,
    gl_context: PossiblyCurrentContext,

That means that the surface is destroyed first, then the surface, and then the skia context. I suggest to make the DirectContext the first field, so that it is dropped first while the surface is still existent.

@marc2332
Copy link
Owner

Thanks @tronical !! Let's see if that fixes this issue. I just pushed some changes in #355 @katyo ! Let me know if that works 🤞 😄

@katyo
Copy link
Contributor Author

katyo commented Oct 23, 2023

@marc2332 I fetched and tested it again but it still crashes. GDB shows same backtrace.

@marc2332 marc2332 moved this to Todo in Freya Planning Sep 21, 2024
@marc2332 marc2332 moved this from Todo to Blocked in Freya Planning Sep 21, 2024
@marc2332 marc2332 changed the title linux: Segmentation fault while closing window bug: Segmentation fault while closing window Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Blocked
Development

No branches or pull requests

3 participants