From 35f25cca63b7bac072cf3a605fcd66c6fb05b9e7 Mon Sep 17 00:00:00 2001 From: Ian Chua Date: Tue, 12 May 2026 11:28:14 +0800 Subject: [PATCH] fix: application crashes on wayland when swtiching to device tab for Bambu printers --- src/OrcaSlicer.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/OrcaSlicer.cpp b/src/OrcaSlicer.cpp index ba52f6787b..0ab121de6a 100644 --- a/src/OrcaSlicer.cpp +++ b/src/OrcaSlicer.cpp @@ -1213,12 +1213,25 @@ int CLI::run(int argc, char **argv) // XInitThreads is needed before GStreamer may use Xlib. On native // Wayland without DISPLAY, GStreamer uses waylandsink (no Xlib). + // Install a custom X11 error handler to prevent the default handler + // from calling exit()/abort() on non-fatal X11 errors. This is + // necessary on XWayland where GDK/X11 operations can produce + // BadWindow errors during widget realization of GStreamer sinks. #if __has_include() { const char* display_env = ::getenv("DISPLAY"); if (display_env && *display_env) { XInitThreads(); } + XSetErrorHandler([](Display* dpy, XErrorEvent* evt) -> int { + char buffer[256]; + XGetErrorText(dpy, evt->error_code, buffer, sizeof(buffer)); + BOOST_LOG_TRIVIAL(error) << boost::format( + "X11 error: %1% (code=%2%, request=%3%, resource=0x%|4$08x|)") + % buffer % static_cast(evt->error_code) + % static_cast(evt->request_code) % evt->resourceid; + return 0; + }); } #endif #endif