diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 43760d0b1..400ef84e9 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -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) { @@ -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); @@ -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, @@ -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;