Fix for recent GLX error bug
authorSam Lantinga <slouken@libsdl.org>
Tue, 23 Jul 2013 19:20:03 -0700
changeset 7512462839f2f408
parent 7511 4ce3cc948a00
child 7513 ec0c3f1eb2de
Fix for recent GLX error bug

Lee Salzman

I messed up in the patch I sent you regarding gobbling up the GLX error codes signaled when trying to create a context. After reading the spec I realized those error codes are relative to a base error that needs to be queried when setting up the GLX extension...

So I have made a patch that fixes it for a user I had who was still getting the bug with my old patch.

Without this patch my previous one won't work, so it is recommended to merge this...
src/video/x11/SDL_x11opengl.c
src/video/x11/SDL_x11opengl.h
     1.1 --- a/src/video/x11/SDL_x11opengl.c	Tue Jul 23 19:18:01 2013 -0700
     1.2 +++ b/src/video/x11/SDL_x11opengl.c	Tue Jul 23 19:20:03 2013 -0700
     1.3 @@ -133,6 +133,7 @@
     1.4  int
     1.5  X11_GL_LoadLibrary(_THIS, const char *path)
     1.6  {
     1.7 +    Display *display;
     1.8      void *handle;
     1.9  
    1.10      if (_this->gl_data) {
    1.11 @@ -186,6 +187,9 @@
    1.12  
    1.13      /* Load function pointers */
    1.14      handle = _this->gl_config.dll_handle;
    1.15 +    _this->gl_data->glXQueryExtension =
    1.16 +        (Bool (*)(Display *, int *, int *))
    1.17 +            GL_LoadFunction(handle, "glXQueryExtension");
    1.18      _this->gl_data->glXGetProcAddress =
    1.19          (void *(*)(const GLubyte *))
    1.20              GL_LoadFunction(handle, "glXGetProcAddressARB");
    1.21 @@ -208,7 +212,8 @@
    1.22          (void (*)(Display*,GLXDrawable,int,unsigned int*))
    1.23              X11_GL_GetProcAddress(_this, "glXQueryDrawable");
    1.24  
    1.25 -    if (!_this->gl_data->glXChooseVisual ||
    1.26 +    if (!_this->gl_data->glXQueryExtension ||
    1.27 +        !_this->gl_data->glXChooseVisual ||
    1.28          !_this->gl_data->glXCreateContext ||
    1.29          !_this->gl_data->glXDestroyContext ||
    1.30          !_this->gl_data->glXMakeCurrent ||
    1.31 @@ -216,6 +221,11 @@
    1.32          return SDL_SetError("Could not retrieve OpenGL functions");
    1.33      }
    1.34  
    1.35 +    display = ((SDL_VideoData *) _this->driverdata)->display;
    1.36 +    if (!_this->gl_data->glXQueryExtension(display, &_this->gl_data->errorBase, &_this->gl_data->eventBase)) {
    1.37 +        return SDL_SetError("GLX is not supported");
    1.38 +    }
    1.39 +
    1.40      /* Initialize extensions */
    1.41      X11_GL_InitExtensions(_this);
    1.42  
    1.43 @@ -504,19 +514,23 @@
    1.44  #define GLXBadProfileARB 13
    1.45  #endif
    1.46  static int (*handler) (Display *, XErrorEvent *) = NULL;
    1.47 +static int errorBase = 0;
    1.48  static int
    1.49  X11_GL_CreateContextErrorHandler(Display * d, XErrorEvent * e)
    1.50  {
    1.51      switch (e->error_code) {
    1.52 -    case GLXBadContext:
    1.53 -    case GLXBadFBConfig:
    1.54 -    case GLXBadProfileARB:
    1.55      case BadRequest:
    1.56      case BadMatch:
    1.57      case BadValue:
    1.58      case BadAlloc:
    1.59          return (0);
    1.60      default:
    1.61 +        if (errorBase && 
    1.62 +            (e->error_code == errorBase + GLXBadContext ||
    1.63 +             e->error_code == errorBase + GLXBadFBConfig ||
    1.64 +             e->error_code == errorBase + GLXBadProfileARB)) {
    1.65 +            return (0);
    1.66 +        }
    1.67          return (handler(d, e));
    1.68      }
    1.69  }
    1.70 @@ -541,6 +555,7 @@
    1.71  
    1.72      /* We do this to create a clean separation between X and GLX errors. */
    1.73      XSync(display, False);
    1.74 +    errorBase = _this->gl_data->errorBase;
    1.75      handler = XSetErrorHandler(X11_GL_CreateContextErrorHandler);
    1.76      XGetWindowAttributes(display, data->xwindow, &xattr);
    1.77      v.screen = screen;
     2.1 --- a/src/video/x11/SDL_x11opengl.h	Tue Jul 23 19:18:01 2013 -0700
     2.2 +++ b/src/video/x11/SDL_x11opengl.h	Tue Jul 23 19:20:03 2013 -0700
     2.3 @@ -29,10 +29,13 @@
     2.4  
     2.5  struct SDL_GLDriverData
     2.6  {
     2.7 +    int errorBase, eventBase;
     2.8 +
     2.9      SDL_bool HAS_GLX_EXT_visual_rating;
    2.10      SDL_bool HAS_GLX_EXT_visual_info;
    2.11      SDL_bool HAS_GLX_EXT_swap_control_tear;
    2.12  
    2.13 +    Bool (*glXQueryExtension) (Display*,int*,int*);
    2.14      void *(*glXGetProcAddress) (const GLubyte*);
    2.15      XVisualInfo *(*glXChooseVisual) (Display*,int,int*);
    2.16      GLXContext (*glXCreateContext) (Display*,XVisualInfo*,GLXContext,Bool);