Crash on wayland
Closed this issue · 3 comments
Principia version
2024.06.28, NixOS package
OS / Hardware
- Platform:
- Operating system: NixOS
- GPU model: AMD Radeon 780M
Summary
principia crashes when run under wayland (SDL_VIDEODRIVER=wayland
). It works fine under X11 (SDL_VIDEODRIVER=x11
)
Steps to reproduce
$ SDL_VIDEODRIVER=wayland principia
I: Starting fifo listener thread
I: chdirring to /nix/store/ljwcc8l3acwngm45m3mqx1bnk50yl53i-principia-2024.06.28/bin/
I: attempting to open /tmp/principia.run O_RDONLY
I: Storage path: /home/fgaz/.principia
I: Redirecting log output to /home/fgaz/.principia/run.log
contents of run.log:
_ _ _
_ __ _ __(_)_ __ ___(_)_ __ (_) __ _
| '_ \| '__| | '_ \ / __| | '_ \| |/ _` |
| |_) | | | | | | | (__| | |_) | | (_| |
| .__/|_| |_|_| |_|\___|_| .__/|_|\__,_|
|_| |_|
Version 36, built Jan 1 1980 00:00:00
I: chdirring to ../
I: chdirring to ./share/principia/
I: Compiled against SDL v2.30.3
I: Linked against SDL v2.30.3
I: Initializing SDL...
I: set initial res to 1015x570
I: num workers (real): 16
I: Loading settings...
I: num workers (user): 16
I: Shadow quality: 1 (1280x720)
I: Creating window...
I: Initializing GLEW...
I: ERROR: Unknown error
I've been able to run Principia with the native Wayland SDL video driver on my Arch system, but I just tested in a NixOS live environment and can reproduce the issue there. I ended up looking at the packaging for my system's GLEW package and saw that it has this patch applied for something with Wayland support, and rebuilding my GLEW package before this commit makes me able to reproduce the crash on Arch too. Seems like upstream GLEW knows about there being issues like this on Wayland: nigels-com/glew#172
The workaround other projects seems to have done is just ignore the GLEW_ERROR_NO_GLX_DISPLAY
error and apparently it will just work like regularly on Wayland, as concerning as it may look. With my rebuilt GLEW without distro patches the following change to Principia makes the game work again:
diff --git a/src/tms/backend/main.cc b/src/tms/backend/main.cc
index 375a03d7..ca9ba0d9 100644
--- a/src/tms/backend/main.cc
+++ b/src/tms/backend/main.cc
@@ -400,7 +400,7 @@ tbackend_init_surface()
tms_infof("Initializing GLEW...");
GLenum err = glewInit();
- if (err != GLEW_OK) {
+ if (err != GLEW_OK && err != GLEW_ERROR_NO_GLX_DISPLAY) {
tms_infof("ERROR: %s", glewGetErrorString(err));
exit(1);
}
I wonder if this workaround would work under NixOS too.
Apparently the fix also fixes our AppImage builds that have previously been broken when trying with the Wayland video driver. So I assume this was it.
I confirm that applying the patch in #174 (comment) fixes the issue for me