src/video/x11/SDL_x11opengl.c
changeset 6988 2aed1beaf5bc
parent 6948 84a71440360d
child 7037 3fedf1f25b94
     1.1 --- a/src/video/x11/SDL_x11opengl.c	Sun Mar 10 09:03:38 2013 -0700
     1.2 +++ b/src/video/x11/SDL_x11opengl.c	Sun Mar 10 09:07:23 2013 -0700
     1.3 @@ -496,6 +496,33 @@
     1.4      return vinfo;
     1.5  }
     1.6  
     1.7 +#ifndef GLXBadContext
     1.8 +#define GLXBadContext 0
     1.9 +#endif
    1.10 +#ifndef GLXBadFBConfig
    1.11 +#define GLXBadFBConfig 9
    1.12 +#endif
    1.13 +#ifndef GLXBadProfileARB
    1.14 +#define GLXBadProfileARB 13
    1.15 +#endif
    1.16 +static int (*handler) (Display *, XErrorEvent *) = NULL;
    1.17 +static int
    1.18 +X11_GL_CreateContextErrorHandler(Display * d, XErrorEvent * e)
    1.19 +{
    1.20 +    switch (e->error_code) {
    1.21 +    case GLXBadContext:
    1.22 +    case GLXBadFBConfig:
    1.23 +    case GLXBadProfileARB:
    1.24 +    case BadRequest:
    1.25 +    case BadMatch:
    1.26 +    case BadValue:
    1.27 +    case BadAlloc:
    1.28 +        return (0);
    1.29 +    default:
    1.30 +        return (handler(d, e));
    1.31 +    }
    1.32 +}
    1.33 +
    1.34  SDL_GLContext
    1.35  X11_GL_CreateContext(_THIS, SDL_Window * window)
    1.36  {
    1.37 @@ -516,6 +543,7 @@
    1.38  
    1.39      /* We do this to create a clean separation between X and GLX errors. */
    1.40      XSync(display, False);
    1.41 +    handler = XSetErrorHandler(X11_GL_CreateContextErrorHandler);
    1.42      XGetWindowAttributes(display, data->xwindow, &xattr);
    1.43      v.screen = screen;
    1.44      v.visualid = XVisualIDFromVisual(xattr.visual);
    1.45 @@ -532,10 +560,7 @@
    1.46                 context to grab the new context creation function */
    1.47              GLXContext temp_context =
    1.48                  _this->gl_data->glXCreateContext(display, vinfo, NULL, True);
    1.49 -            if (!temp_context) {
    1.50 -                SDL_SetError("Could not create GL context");
    1.51 -                return NULL;
    1.52 -            } else {
    1.53 +            if (temp_context) {
    1.54                  /* max 8 attributes plus terminator */
    1.55                  int attribs[9] = {
    1.56                      GLX_CONTEXT_MAJOR_VERSION_ARB,
    1.57 @@ -609,7 +634,8 @@
    1.58          XFree(vinfo);
    1.59      }
    1.60      XSync(display, False);
    1.61 -
    1.62 +    XSetErrorHandler(handler);
    1.63 +    
    1.64      if (!context) {
    1.65          SDL_SetError("Could not create GL context");
    1.66          return NULL;