From 2ece101f0e7d071b6efa44cfca19419c6d985a36 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 21 Jan 2013 20:19:20 +0100 Subject: [PATCH] Added X error text to context creation failure. --- src/glx_context.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/glx_context.c b/src/glx_context.c index 0730be25..40be4088 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -67,8 +67,7 @@ static _GLFW_TLS _GLFWwindow* _glfwCurrentWindow = NULL; //======================================================================== -// Error handler used when creating a context with the GLX_ARB_create_context -// extension set +// Error handler used when creating a context //======================================================================== static int errorHandler(Display *display, XErrorEvent* event) @@ -411,6 +410,9 @@ int _glfwCreateContext(_GLFWwindow* window, } } + _glfwErrorCode = Success; + XSetErrorHandler(errorHandler); + if (_glfw.glx.ARB_create_context) { int index = 0, mask = 0, flags = 0, strategy = 0; @@ -468,13 +470,6 @@ int _glfwCreateContext(_GLFWwindow* window, setGLXattrib(None, None); - // This is the only place we set an Xlib error handler, and we only do - // it because glXCreateContextAttribsARB generates a BadMatch error if - // the requested OpenGL version is unavailable (instead of a civilized - // response like returning NULL) - _glfwErrorCode = Success; - XSetErrorHandler(errorHandler); - window->glx.context = _glfw.glx.CreateContextAttribsARB(_glfw.x11.display, *native, @@ -482,9 +477,6 @@ int _glfwCreateContext(_GLFWwindow* window, True, attribs); - // We are done, so unset the error handler again (see above) - XSetErrorHandler(NULL); - if (window->glx.context == NULL) { // HACK: This is a fallback for the broken Mesa implementation of @@ -502,11 +494,21 @@ int _glfwCreateContext(_GLFWwindow* window, else window->glx.context = createLegacyContext(window, *native, share); + XSetErrorHandler(NULL); + XFree(native); if (window->glx.context == NULL) { - _glfwInputError(GLFW_PLATFORM_ERROR, "GLX: Failed to create context"); + char buffer[8192]; + XGetErrorText(_glfw.x11.display, + _glfwErrorCode, + buffer, sizeof(buffer)); + + _glfwInputError(GLFW_PLATFORM_ERROR, + "GLX: Failed to create context: %s", + buffer); + return GL_FALSE; }