From b5b345909c857862e26ffdf057e57401a9549b8f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 2 Jul 2020 19:35:27 +0200 Subject: Fix crash when closing target window --- src/main.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 62302b4..95d75db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,6 +46,9 @@ extern "C" { #include #include #include +#include +#include +#include #include #include @@ -566,6 +569,23 @@ std::string GetTrackedDeviceString( vr::TrackedDeviceIndex_t unDevice, vr::Track return sResult; } +static int xerror(Display *dpy, XErrorEvent *ee) { + if (ee->error_code == BadWindow + || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch) + || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable) + || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable) + || (ee->request_code == X_PolySegment && ee->error_code == BadDrawable) + || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch) + || (ee->request_code == X_GrabButton && ee->error_code == BadAccess) + || (ee->request_code == X_GrabKey && ee->error_code == BadAccess) + || (ee->request_code == X_CopyArea && ee->error_code == BadDrawable) + || (ee->request_code == X_GLXCreatePixmap && ee->error_code == BadMatch)) + return 0; + fprintf(stderr, "vrwm: fatal error: request code=%d, error code=%d\n", + ee->request_code, ee->error_code); + return 0; /* may call exit */ /* TODO: xerrorxlib(dpy, ee); */ +} + //----------------------------------------------------------------------------- // Purpose: @@ -579,6 +599,8 @@ bool CMainApplication::BInit() return false; } + XSetErrorHandler(xerror); + XWindowAttributes xwa; if(!XGetWindowAttributes(x_display, src_window_id, &xwa)) { fprintf(stderr, "Error: Invalid window id: %lud\n", src_window_id); -- cgit v1.2.3