From f50b668b7334f8aafae6b254fee92e82dc1f6a86 Mon Sep 17 00:00:00 2001 From: siavash Date: Tue, 9 Jul 2013 12:13:05 +0430 Subject: [PATCH] Unified XErrorHandlers. --- src/glx_context.c | 34 +++++++++++++++++++++++----------- src/x11_init.c | 19 ++----------------- src/x11_platform.h | 4 ++++ 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/glx_context.c b/src/glx_context.c index 724037f4..2b302783 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -45,14 +45,32 @@ void (*glXGetProcAddressEXT(const GLubyte* procName))(); #endif -// Error handler used when creating a context +// Error handler used when creating a context and blank cursor // static int errorHandler(Display *display, XErrorEvent* event) { - _glfw.glx.errorCode = event->error_code; + char buffer[8192]; + XGetErrorText(display, + event->error_code, + buffer, sizeof(buffer)); + + _glfwInputError(GLFW_PLATFORM_ERROR, "X11 failure: %s", buffer); + return 0; } +void _glfwGrabXErrorHandler(void) +{ + XSetErrorHandler(errorHandler); +} + +void _glfwReleaseXErrorHandler(void) +{ + // Syncing to make sure all commands are processed + XSync(_glfw.x11.display, False); + XSetErrorHandler(NULL); +} + // Returns the specified attribute of the specified GLXFBConfig // NOTE: Do not call this unless we have found GLX 1.3+ or GLX_SGIX_fbconfig // @@ -428,7 +446,7 @@ int _glfwCreateContext(_GLFWwindow* window, } _glfw.glx.errorCode = Success; - XSetErrorHandler(errorHandler); + _glfwGrabXErrorHandler(); if (_glfw.glx.ARB_create_context) { @@ -511,18 +529,12 @@ int _glfwCreateContext(_GLFWwindow* window, else window->glx.context = createLegacyContext(window, native, share); - XSetErrorHandler(NULL); + _glfwReleaseXErrorHandler(); if (window->glx.context == NULL) { - char buffer[8192]; - XGetErrorText(_glfw.x11.display, - _glfw.glx.errorCode, - buffer, sizeof(buffer)); - _glfwInputError(GLFW_PLATFORM_ERROR, - "GLX: Failed to create context: %s", - buffer); + "GLX: Failed to create context."); return GL_FALSE; } diff --git a/src/x11_init.c b/src/x11_init.c index 709ed04e..881d66ac 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -37,20 +37,6 @@ #include -// Error handler used when creating a blank cursor -// -static int errorHandler(Display *display, XErrorEvent* event) -{ - char buffer[8192]; - XGetErrorText(display, - event->error_code, - buffer, sizeof(buffer)); - - _glfwInputError(GLFW_PLATFORM_ERROR, "X11: Failed to create a blank cursor: %s", buffer); - - return 0; -} - // Translate an X11 key code to a GLFW key code. // static int translateKey(int keyCode) @@ -567,7 +553,7 @@ static Cursor createNULLCursor(void) XColor col; Cursor cursor; - XSetErrorHandler(errorHandler); + _glfwGrabXErrorHandler(); cursormask = XCreatePixmap(_glfw.x11.display, _glfw.x11.root, 1, 1, 1); xgc.function = GXclear; @@ -582,8 +568,7 @@ static Cursor createNULLCursor(void) XFreePixmap(_glfw.x11.display, cursormask); XFreeGC(_glfw.x11.display, gc); - XSync(_glfw.x11.display, False); - XSetErrorHandler(NULL); + _glfwReleaseXErrorHandler(); return cursor; } diff --git a/src/x11_platform.h b/src/x11_platform.h index 1ac323dc..775e9c19 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -256,4 +256,8 @@ unsigned long _glfwGetWindowProperty(Window window, Atom type, unsigned char** value); +// X11 error handler +void _glfwGrabXErrorHandler(void); +void _glfwReleaseXErrorHandler(void); + #endif // _x11_platform_h_