From 07a8635c550303b44c0a751ef24ad1b1768df7f8 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 31 Mar 2020 19:29:54 +0200 Subject: add debug handlers for x11 --- src/main.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index ff88a8e..4836189 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -63,6 +63,31 @@ static bool x11_supports_composite_named_window_pixmap(Display *dpy) { (major_version > 0 || minor_version >= 2); } +static int x11_error_handler(Display *dpy, XErrorEvent *ev) { + char type_str[128]; + XGetErrorText(dpy, ev->type, type_str, sizeof(type_str)); + + char major_opcode_str[128]; + XGetErrorText(dpy, ev->type, major_opcode_str, sizeof(major_opcode_str)); + + char minor_opcode_str[128]; + XGetErrorText(dpy, ev->type, minor_opcode_str, sizeof(minor_opcode_str)); + + fprintf(stderr, + "X Error of failed request: %s\n" + "Major opcode of failed request: %d (%s)\n" + "Minor opcode of failed request: %d (%s)\n" + "Serial number of failed request: %d\n", + type_str, + ev->request_code, major_opcode_str, + ev->minor_code, minor_opcode_str); + return 0; +} + +static int x11_io_error_handler(Display *dpy) { + return 0; +} + static void cleanup_window_pixmap(Display *dpy, WindowPixmap &pixmap) { if (pixmap.target_texture_id) { glDeleteTextures(1, &pixmap.target_texture_id); @@ -468,6 +493,12 @@ int main(int argc, char **argv) { glfwMakeContextCurrent(window); glfwSwapInterval(0); +#define DEBUG +#if defined(DEBUG) + XSetErrorHandler(x11_error_handler); + XSetIOErrorHandler(x11_io_error_handler); +#endif + glewExperimental = GL_TRUE; GLenum nGlewError = glewInit(); if (nGlewError != GLEW_OK) { -- cgit v1.2.3