mirror of
https://github.com/glfw/glfw.git
synced 2024-11-26 20:11:58 +00:00
Merge pull request #86 from siavashserver/master
Added utility functions for X11 error handler.
This commit is contained in:
commit
f67c7b49ab
@ -45,14 +45,32 @@ void (*glXGetProcAddressEXT(const GLubyte* procName))();
|
|||||||
#endif
|
#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)
|
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;
|
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
|
||||||
//
|
//
|
||||||
@ -428,7 +446,7 @@ int _glfwCreateContext(_GLFWwindow* window,
|
|||||||
}
|
}
|
||||||
|
|
||||||
_glfw.glx.errorCode = Success;
|
_glfw.glx.errorCode = Success;
|
||||||
XSetErrorHandler(errorHandler);
|
_glfwGrabXErrorHandler();
|
||||||
|
|
||||||
if (_glfw.glx.ARB_create_context)
|
if (_glfw.glx.ARB_create_context)
|
||||||
{
|
{
|
||||||
@ -511,18 +529,12 @@ int _glfwCreateContext(_GLFWwindow* window,
|
|||||||
else
|
else
|
||||||
window->glx.context = createLegacyContext(window, native, share);
|
window->glx.context = createLegacyContext(window, native, share);
|
||||||
|
|
||||||
XSetErrorHandler(NULL);
|
_glfwReleaseXErrorHandler();
|
||||||
|
|
||||||
if (window->glx.context == NULL)
|
if (window->glx.context == NULL)
|
||||||
{
|
{
|
||||||
char buffer[8192];
|
|
||||||
XGetErrorText(_glfw.x11.display,
|
|
||||||
_glfw.glx.errorCode,
|
|
||||||
buffer, sizeof(buffer));
|
|
||||||
|
|
||||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
"GLX: Failed to create context: %s",
|
"GLX: Failed to create context.");
|
||||||
buffer);
|
|
||||||
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -553,7 +553,7 @@ static Cursor createNULLCursor(void)
|
|||||||
XColor col;
|
XColor col;
|
||||||
Cursor cursor;
|
Cursor cursor;
|
||||||
|
|
||||||
// TODO: Add error checks
|
_glfwGrabXErrorHandler();
|
||||||
|
|
||||||
cursormask = XCreatePixmap(_glfw.x11.display, _glfw.x11.root, 1, 1, 1);
|
cursormask = XCreatePixmap(_glfw.x11.display, _glfw.x11.root, 1, 1, 1);
|
||||||
xgc.function = GXclear;
|
xgc.function = GXclear;
|
||||||
@ -568,6 +568,8 @@ static Cursor createNULLCursor(void)
|
|||||||
XFreePixmap(_glfw.x11.display, cursormask);
|
XFreePixmap(_glfw.x11.display, cursormask);
|
||||||
XFreeGC(_glfw.x11.display, gc);
|
XFreeGC(_glfw.x11.display, gc);
|
||||||
|
|
||||||
|
_glfwReleaseXErrorHandler();
|
||||||
|
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,4 +256,8 @@ unsigned long _glfwGetWindowProperty(Window window,
|
|||||||
Atom type,
|
Atom type,
|
||||||
unsigned char** value);
|
unsigned char** value);
|
||||||
|
|
||||||
|
// X11 error handler
|
||||||
|
void _glfwGrabXErrorHandler(void);
|
||||||
|
void _glfwReleaseXErrorHandler(void);
|
||||||
|
|
||||||
#endif // _x11_platform_h_
|
#endif // _x11_platform_h_
|
||||||
|
Loading…
Reference in New Issue
Block a user