slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.55k stars 601 forks source link

Panic when trying to show window on GLX display with femtovg and Skia/OpenGL renderers #2269

Closed ngocnha closed 10 months ago

ngocnha commented 1 year ago

(edited by @tronical )

Running with the FemtoVG or Skia OpenGL renderers against a GLX accelerated display panics.

The backtrace below is from an earlier symptom.

Acceptance criteria:

RUST_BACKTRACE=1 target/debug/slint-app
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { raw_code: Some(160), raw_os_message: Some("GLXBadDrawable"), kind: BadSurface }', /home/whiteseed/.cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-backend-winit-0.3.5/renderer/femtovg/glcontext.rs:172:75
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14
   2: core::result::unwrap_failed
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/result.rs:1791:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/result.rs:1113:23
   4: i_slint_backend_winit::renderer::femtovg::glcontext::OpenGLContext::new_context
             at /home/whiteseed/.cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-backend-winit-0.3.5/renderer/femtovg/glcontext.rs:172:29
   5: <i_slint_backend_winit::renderer::femtovg::FemtoVGRenderer as i_slint_backend_winit::renderer::WinitCompatibleRenderer>::show
             at /home/whiteseed/.cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-backend-winit-0.3.5/renderer/femtovg.rs:58:30
   6: <i_slint_backend_winit::glwindow::GLWindow<Renderer> as i_slint_core::window::WindowAdapterSealed>::show::{{closure}}
             at /home/whiteseed/.cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-backend-winit-0.3.5/glwindow.rs:545:13
   7: core::ops::function::FnOnce::call_once
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/ops/function.rs:507:5
   8: i_slint_backend_winit::glwindow::GLWindow<Renderer>::call_with_event_loop
             at /home/whiteseed/.cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-backend-winit-0.3.5/glwindow.rs:175:9
   9: <i_slint_backend_winit::glwindow::GLWindow<Renderer> as i_slint_core::window::WindowAdapterSealed>::show
             at /home/whiteseed/.cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-backend-winit-0.3.5/glwindow.rs:390:9
  10: i_slint_core::window::WindowInner::show
             at /home/whiteseed/.cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-core-0.3.5/window.rs:615:9
  11: i_slint_core::api::Window::show
             at /home/whiteseed/.cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-core-0.3.5/api.rs:346:9
  12: <slint_app::slint_generatedAppWindow::AppWindow as i_slint_core::api::ComponentHandle>::show
             at ./target/debug/build/slint-app-952588998e8ffc3d/out/appwindow.rs:1417:14
  13: <slint_app::slint_generatedAppWindow::AppWindow as i_slint_core::api::ComponentHandle>::run
             at ./target/debug/build/slint-app-952588998e8ffc3d/out/appwindow.rs:1412:14
  14: slint_app::main
             at ./src/main.rs:12:5
  15: core::ops::function::FnOnce::call_once
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
tronical commented 1 year ago

I suspect that somehow the window is not created to be suitable for GLX rendering :(

ogoffart commented 1 year ago

Under what condition is this triggered?

We should be able to give a better error message at least when this happen.

ngocnha commented 1 year ago

Maybe the issue occurred while I was using the NVIDIA graphics mode. When I switched to Hybrid mode today, it started working again.


Hardware Model: Micro-Star International Co., Ltd. GF63 Thin 8RCS Memory: 16.0 GiB Processor: Intel® Core™ i7-8750H CPU @ 2.20GHz × 12 Graphics: NVIDIA Corporation GP107M [GeForce GTX 1050 Mobile] / Mesa Intel® UHD Graphic

OS Name: Pop!_OS 22.04 LTS OS Type: 64-bit GNOME Version: 42.5 Windowing System: X11

NVDIA Driver: 525.85.05

jeandudey commented 1 year ago

Getting the same error using the same same driver version on a RTX 3070, may be related to NVIDIA X11 implementation.

tronical commented 1 year ago

I can reproduce this error locally (yay)

tronical commented 1 year ago

I think this is somewhat related to https://github.com/rust-windowing/winit/issues/2681 . Until winit can tell us what visual it picked, we need have two code paths:

  1. On WGL, create the Window first, then select a window-compatible GL config.
  2. On GLX select the GL config first, retrieve the x11 visual info and pass it to the winit window builder with with_x11_visual - that way the visuals match and this error should go away.
tronical commented 1 year ago

I made a fix for this that works with FemtoVG. With Skia the situation is a little more complicated, because the internal Skia renderer API is built on two assumptions:

  1. The renderer does not depend on winit (for use in experimental C++ platform API).
  2. The window exists before calling show() on the renderer.

So the "easy" fix, adding WindowBuilder to the API and using glutin-winit doesn't quite work.

I tried to fix this by creating the corresponding glutin config that can provide the x11 visual in the skia renderer constructor (only on x11), then pass the visual to the window builder, and then continue as normal. Unfortunately this crashes in the Skia GL code. Branch is at https://github.com/slint-ui/slint/tree/simon/wip/skia-glx

tronical commented 10 months ago

We should not panic anymore since https://github.com/slint-ui/slint/pull/2907