Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed bug 1749 - SDL_GL_CreateContext() causes fatal X11 protocol err…
Browse files Browse the repository at this point in the history
…ors that should just be caught instead

Lee Salzman

When using SDL_GL_CreateContext() to create a >= 3.0 version or core/forward-compatible context, internally glXCreateContextAttribsARB is used. Mesa in particular seems to be having trouble with this call and returning all sorts of errors, so it is dangerous to poll for the highest GL version by using calls to SDL_GL_CreateContext unless you are sure, a priori, that the call will suceed, defeating the point of its use.

X11 protocol errors are of the following form, with varying details depending on user, but the cause is always SDL_GL_CreateContext as above...

X Error of failed request:  GLXBadFBConfig
  Major opcode of failed request:  153 (GLX)
  Minor opcode of failed request:  34 ()
  Serial number of failed request:  215
  Current serial number in output stream:  221

These sorts of errors can be temporarily filtered out by setting an X11 error handler to catch and ignore them, which is safe with respect to SDL_GL_CreateContext behavior because this function is allowed to return NULL to indicate failure.

A patch is attached to do this temporary filtering/catching of errors generated by trying to use glXCreateContextAttribs and friends...
  • Loading branch information
slouken committed Mar 10, 2013
1 parent 41e0666 commit 020858f
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/video/x11/SDL_x11opengl.c
Expand Up @@ -496,6 +496,33 @@ X11_GL_GetVisual(_THIS, Display * display, int screen)
return vinfo;
}

#ifndef GLXBadContext
#define GLXBadContext 0
#endif
#ifndef GLXBadFBConfig
#define GLXBadFBConfig 9
#endif
#ifndef GLXBadProfileARB
#define GLXBadProfileARB 13
#endif
static int (*handler) (Display *, XErrorEvent *) = NULL;
static int
X11_GL_CreateContextErrorHandler(Display * d, XErrorEvent * e)
{
switch (e->error_code) {
case GLXBadContext:
case GLXBadFBConfig:
case GLXBadProfileARB:
case BadRequest:
case BadMatch:
case BadValue:
case BadAlloc:
return (0);
default:
return (handler(d, e));
}
}

SDL_GLContext
X11_GL_CreateContext(_THIS, SDL_Window * window)
{
Expand All @@ -516,6 +543,7 @@ X11_GL_CreateContext(_THIS, SDL_Window * window)

/* We do this to create a clean separation between X and GLX errors. */
XSync(display, False);
handler = XSetErrorHandler(X11_GL_CreateContextErrorHandler);
XGetWindowAttributes(display, data->xwindow, &xattr);
v.screen = screen;
v.visualid = XVisualIDFromVisual(xattr.visual);
Expand All @@ -532,10 +560,7 @@ X11_GL_CreateContext(_THIS, SDL_Window * window)
context to grab the new context creation function */
GLXContext temp_context =
_this->gl_data->glXCreateContext(display, vinfo, NULL, True);
if (!temp_context) {
SDL_SetError("Could not create GL context");
return NULL;
} else {
if (temp_context) {
/* max 8 attributes plus terminator */
int attribs[9] = {
GLX_CONTEXT_MAJOR_VERSION_ARB,
Expand Down Expand Up @@ -609,7 +634,8 @@ X11_GL_CreateContext(_THIS, SDL_Window * window)
XFree(vinfo);
}
XSync(display, False);

XSetErrorHandler(handler);

if (!context) {
SDL_SetError("Could not create GL context");
return NULL;
Expand Down

0 comments on commit 020858f

Please sign in to comment.