Przeglądaj źródła

Cleaned up X error handler work.

Camilla Berglund 12 lat temu
rodzic
commit
45653c5549
4 zmienionych plików z 53 dodań i 34 usunięć
  1. 2 31
      src/glx_context.c
  2. 0 3
      src/glx_platform.h
  3. 47 0
      src/x11_init.c
  4. 4 0
      src/x11_platform.h

+ 2 - 31
src/glx_context.c

@@ -45,32 +45,6 @@ void (*glXGetProcAddressEXT(const GLubyte* procName))();
 #endif
 #endif
 
 
 
 
-// Error handler used when creating a context and 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 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
 // Returns the specified attribute of the specified GLXFBConfig
 // NOTE: Do not call this unless we have found GLX 1.3+ or GLX_SGIX_fbconfig
 // NOTE: Do not call this unless we have found GLX 1.3+ or GLX_SGIX_fbconfig
 //
 //
@@ -445,7 +419,6 @@ int _glfwCreateContext(_GLFWwindow* window,
         }
         }
     }
     }
 
 
-    _glfw.glx.errorCode = Success;
     _glfwGrabXErrorHandler();
     _glfwGrabXErrorHandler();
 
 
     if (_glfw.glx.ARB_create_context)
     if (_glfw.glx.ARB_create_context)
@@ -517,7 +490,7 @@ int _glfwCreateContext(_GLFWwindow* window,
             // HACK: This is a fallback for the broken Mesa implementation of
             // HACK: This is a fallback for the broken Mesa implementation of
             // GLX_ARB_create_context_profile, which fails default 1.0 context
             // GLX_ARB_create_context_profile, which fails default 1.0 context
             // creation with a GLXBadProfileARB error in violation of the spec
             // creation with a GLXBadProfileARB error in violation of the spec
-            if (_glfw.glx.errorCode == _glfw.glx.errorBase + GLXBadProfileARB &&
+            if (_glfw.x11.errorCode == _glfw.glx.errorBase + GLXBadProfileARB &&
                 wndconfig->clientAPI == GLFW_OPENGL_API &&
                 wndconfig->clientAPI == GLFW_OPENGL_API &&
                 wndconfig->glProfile == GLFW_OPENGL_ANY_PROFILE &&
                 wndconfig->glProfile == GLFW_OPENGL_ANY_PROFILE &&
                 wndconfig->glForward == GL_FALSE)
                 wndconfig->glForward == GL_FALSE)
@@ -533,9 +506,7 @@ int _glfwCreateContext(_GLFWwindow* window,
 
 
     if (window->glx.context == NULL)
     if (window->glx.context == NULL)
     {
     {
-        _glfwInputError(GLFW_PLATFORM_ERROR,
-                        "GLX: Failed to create context.");
-
+        _glfwInputXError(GLFW_PLATFORM_ERROR, "GLX: Failed to create context");
         return GL_FALSE;
         return GL_FALSE;
     }
     }
 
 

+ 0 - 3
src/glx_platform.h

@@ -97,9 +97,6 @@ typedef struct _GLFWlibraryGLX
     // TLS key for per-thread current context/window
     // TLS key for per-thread current context/window
     pthread_key_t   current;
     pthread_key_t   current;
 
 
-    // GLX error code received by Xlib error callback
-    int             errorCode;
-
     // GLX extensions
     // GLX extensions
     PFNGLXSWAPINTERVALSGIPROC             SwapIntervalSGI;
     PFNGLXSWAPINTERVALSGIPROC             SwapIntervalSGI;
     PFNGLXSWAPINTERVALEXTPROC             SwapIntervalEXT;
     PFNGLXSWAPINTERVALEXTPROC             SwapIntervalEXT;

+ 47 - 0
src/x11_init.c

@@ -570,6 +570,12 @@ static Cursor createNULLCursor(void)
 
 
     _glfwReleaseXErrorHandler();
     _glfwReleaseXErrorHandler();
 
 
+    if (cursor == None)
+    {
+        _glfwInputXError(GLFW_PLATFORM_ERROR,
+                         "X11: Failed to create null cursor");
+    }
+
     return cursor;
     return cursor;
 }
 }
 
 
@@ -584,6 +590,47 @@ static void terminateDisplay(void)
     }
     }
 }
 }
 
 
+// X error handler
+//
+static int errorHandler(Display *display, XErrorEvent* event)
+{
+    _glfw.x11.errorCode = event->error_code;
+    return 0;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+//////                       GLFW internal API                      //////
+//////////////////////////////////////////////////////////////////////////
+
+// Install the X error handler
+//
+void _glfwGrabXErrorHandler(void)
+{
+    _glfw.x11.errorCode = Success;
+    XSetErrorHandler(errorHandler);
+}
+
+// Remove the X error handler
+//
+void _glfwReleaseXErrorHandler(void)
+{
+    // Synchronize to make sure all commands are processed
+    XSync(_glfw.x11.display, False);
+    XSetErrorHandler(NULL);
+}
+
+// Report X error
+//
+void _glfwInputXError(int error, const char* message)
+{
+    char buffer[8192];
+    XGetErrorText(_glfw.x11.display, _glfw.x11.errorCode,
+                  buffer, sizeof(buffer));
+
+    _glfwInputError(error, "%s: %s", message, buffer);
+}
+
 
 
 //////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////
 //////                       GLFW platform API                      //////
 //////                       GLFW platform API                      //////

+ 4 - 0
src/x11_platform.h

@@ -137,6 +137,9 @@ typedef struct _GLFWlibraryX11
     // True if window manager supports EWMH
     // True if window manager supports EWMH
     GLboolean       hasEWMH;
     GLboolean       hasEWMH;
 
 
+    // Error code received by the X error handler
+    int             errorCode;
+
     struct {
     struct {
         GLboolean   available;
         GLboolean   available;
         int         eventBase;
         int         eventBase;
@@ -259,5 +262,6 @@ unsigned long _glfwGetWindowProperty(Window window,
 // X11 error handler
 // X11 error handler
 void _glfwGrabXErrorHandler(void);
 void _glfwGrabXErrorHandler(void);
 void _glfwReleaseXErrorHandler(void);
 void _glfwReleaseXErrorHandler(void);
+void _glfwInputXError(int error, const char* message);
 
 
 #endif // _x11_platform_h_
 #endif // _x11_platform_h_