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

slint preview crash in winit: `XOpenDisplayFailed` #4185

Closed zrz4066 closed 9 months ago

zrz4066 commented 10 months ago

Vs code open slint project in ubuntu on WLS2 WSL2 Ubuntu22.04 ,slint preiew crash

thread 'main' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.4/src/platform_impl/linux/mod.rs:787:62: called Result::unwrap() on an Err value: XOpenDisplayFailed note: run with RUST_BACKTRACE=1 environment variable to display a backtrace [Info - 9:56:19 AM] Connection to server got closed. Server will restart. true The Slint Language Server crashed. This is a bug. Please open an issue on https://github.com/slint-ui/slint/issues thread 'main' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.4/src/platform_impl/linux/mod.rs:787:62: called Result::unwrap() on an Err value: XOpenDisplayFailed note: run with RUST_BACKTRACE=1 environment variable to display a backtrace [Info - 9:56:38 AM] Connection to server got closed. Server will restart. true The Slint Language Server crashed. This is a bug. Please open an issue on https://github.com/slint-ui/slint/issues thread 'main' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.4/src/platform_impl/linux/mod.rs:787:62: called Result::unwrap() on an Err value: XOpenDisplayFailed note: run with RUST_BACKTRACE=1 environment variable to display a backtrace [Info - 9:57:09 AM] Connection to server got closed. Server will restart. true The Slint Language Server crashed. This is a bug. Please open an issue on https://github.com/slint-ui/slint/issues

ogoffart commented 10 months ago

Thanks for the bug report.

This seems to be a bug in winit. Winit should ideally report the error instead of panicking. It shouldn't unwrap there, but return an error instead: https://github.com/rust-windowing/winit/blob/cc33212479b5c9e75ff6ceb16f7a817ddf9950f2/src/platform_impl/linux/mod.rs#L794

The cause seems to be that it cannot open the X11 display, so maybe the DISPLAY env is not set correctly or some other config problem.

If only winit was reporting the good error, we could display it properly in vscode instead of having a panic like this.

What we should do is fix the bug upstream, or at least report it there. And then make sure that the lsp report the error to vscode properly when this happens.

tronical commented 10 months ago

It's also a little odd that we end up at the X11 stage. WSL supports wayland, so that should have been tried first and that should work (we spent some time fixing that, with softbuffer fallback, etc.). @zrz4066 if you open a wsl bash shell, do you have the WAYLAND_DISPLAY environment variable set?

ogoffart commented 9 months ago

The winit bug has been fixed with https://github.com/rust-windowing/winit/pull/3355 But now i'd need to test what happens when winit report an error. That is a duplicated of https://github.com/slint-ui/slint/issues/204