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: