From 2c6ad763afa63e3326eef043eb0b2a87854cce9f Mon Sep 17 00:00:00 2001 From: Nigel Stewart Date: Sun, 13 Nov 2016 12:08:32 +1000 Subject: [PATCH] glxewInit check for current X11 display rather than crashing --- auto/src/glew_init_glx.c | 8 ++++++-- auto/src/glew_tail.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/auto/src/glew_init_glx.c b/auto/src/glew_init_glx.c index 159e45d..8c4596e 100644 --- a/auto/src/glew_init_glx.c +++ b/auto/src/glew_init_glx.c @@ -14,9 +14,13 @@ GLboolean glxewGetExtension (const char* name) GLenum glxewInit () { + Display* display; int major, minor; const GLubyte* extStart; const GLubyte* extEnd; + /* check for a display */ + display = glXGetCurrentDisplay(); + if (display == NULL) return GLEW_ERROR_NO_GLX_DISPLAY; /* initialize core GLX 1.2 */ if (_glewInit_GLX_VERSION_1_2()) return GLEW_ERROR_GLX_VERSION_11_ONLY; /* initialize flags */ @@ -26,7 +30,7 @@ GLenum glxewInit () GLXEW_VERSION_1_3 = GL_TRUE; GLXEW_VERSION_1_4 = GL_TRUE; /* query GLX version */ - glXQueryVersion(glXGetCurrentDisplay(), &major, &minor); + glXQueryVersion(display, &major, &minor); if (major == 1 && minor <= 3) { switch (minor) @@ -46,7 +50,7 @@ GLenum glxewInit () /* query GLX extension string */ extStart = 0; if (glXGetCurrentDisplay != NULL) - extStart = (const GLubyte*)glXGetClientString(glXGetCurrentDisplay(), GLX_EXTENSIONS); + extStart = (const GLubyte*)glXGetClientString(display, GLX_EXTENSIONS); if (extStart == 0) extStart = (const GLubyte *)""; extEnd = extStart + _glewStrLen(extStart); diff --git a/auto/src/glew_tail.h b/auto/src/glew_tail.h index ce7ff3c..09daade 100644 --- a/auto/src/glew_tail.h +++ b/auto/src/glew_tail.h @@ -6,6 +6,7 @@ #define GLEW_ERROR_NO_GL_VERSION 1 /* missing GL version */ #define GLEW_ERROR_GL_VERSION_10_ONLY 2 /* Need at least OpenGL 1.1 */ #define GLEW_ERROR_GLX_VERSION_11_ONLY 3 /* Need at least GLX 1.2 */ +#define GLEW_ERROR_NO_GLX_DISPLAY 4 /* Need GLX display for GLX support */ /* string codes */ #define GLEW_VERSION 1