From f465546a837fe1dd749bbb21d7575cc5d2498628 Mon Sep 17 00:00:00 2001 From: hongquanli <9373466+hongquanli@users.noreply.github.com> Date: Tue, 7 Jul 2026 00:11:18 -0400 Subject: [PATCH] Fix startup crash on Linux Wayland by falling back to XWayland (xcb) On native Wayland sessions, PyQt5 + vispy (OpenGL) fails to create an EGL surface, so the viewer crashes immediately on launch: The Wayland connection experienced a fatal error: Invalid argument Could not create EGL surface (EGL error 0x3000) QOpenGLWidget: Failed to make context current Default QT_QPA_PLATFORM to "xcb" (XWayland) when running on Linux under Wayland, unless the user has already set a Qt platform. XWayland renders reliably and this leaves X11 sessions and explicit overrides untouched. Co-Authored-By: Claude Opus 4.8 --- ndviewer_light/core.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ndviewer_light/core.py b/ndviewer_light/core.py index 0dc470d..09674a9 100644 --- a/ndviewer_light/core.py +++ b/ndviewer_light/core.py @@ -4019,8 +4019,22 @@ def closeEvent(self, event): def main(dataset_path: str = None): """Launch lightweight viewer.""" + import os + import platform import sys + # On Linux Wayland sessions, PyQt5 + vispy (OpenGL) fails to create an EGL + # surface ("Could not create EGL surface", "QOpenGLWidget: Failed to make + # context current"), so the viewer crashes on startup. Fall back to + # XWayland (xcb), which renders reliably, unless the user has already + # chosen a Qt platform. + if ( + platform.system() == "Linux" + and os.environ.get("WAYLAND_DISPLAY") + and "QT_QPA_PLATFORM" not in os.environ + ): + os.environ["QT_QPA_PLATFORM"] = "xcb" + app = QApplication(sys.argv) if dataset_path: