rust-windowing / rust-windowing/winit
Impossible to recover from failed Wayland initialization
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 6.2k
- Forks
- 1.3k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 9
Description
Description
On NixOS-WSL, WAYLAND_DISPLAY is defined as wayland-0, but the wayland compositor fails for some reason, with the error Could not find wayland compositor. If I unset WAYLAND_DISPLAY, this forces winit to use X11, which does work. While winit will fallback to X11 if it can't find Wayland, it will not fallback to X11 if it finds Wayland but Wayland throws some kind of error (which is probably reasonable). However, this failed event_loop creation attempt counts as initializing the event_loop, so I can't manually unset WAYLAND_DISPLAY from inside the program and try again, because I get EventLoop can't be recreated.
The reason you can't easily recreate an eventloop is documented in #2431, but the reason cited there is
event loop is a connection to the display server in the first place, dropping it will drop all the windows present, it's more of an exception on macOS, it's not possible at all on X11/Wayland.
Which is very weird, because the error I got was that no connection could be made to the display server! It seems like it should be possible to recreate the event loop if you never actually succeeded in making one, especially if it failed before a connection to the display server was ever established.
While it might be interesting to figure out why wayland is failing on WSL, all I really care about is having a second chance to create an EventLoop if the creation fails due to not being able to connect to the wayland display server. Alternatively, winit could commit to falling back to X11 if Wayland fails for any reason, or have some kind of with_fallback option when creating the event_loop to opt-in to this behavior.
Debugging output
thread 'main' panicked at examples/basic-rs/main.rs:215:73:
called `Result::unwrap()` on an `Err` value: os error at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winit-0.30.11/src/platform_impl/linux/wayland/event_loop/mod.rs:89: Could not find wayland compositor
Window isn't shown unless you draw
- I understand that windows aren't shown on Wayland unless I draw and present to them.
Winit version
0.30.11
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at src/platform_impl/linux/wayland/event_loop/mod.rs:89 and trace how a failed Wayland EventLoop creation records initialization state. Compare that path with the recreation restriction described in issue #2431. Done should provide a defined way to recover after a failed display connection, or clearly establish the intended fallback behavior, with regression coverage for the reported failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100