diff --git a/readme.html b/readme.html
index a5b5ddd2..fb08e385 100644
--- a/readme.html
+++ b/readme.html
@@ -292,6 +292,7 @@ version of GLFW.
Removed GLFWCALL
and GLFWAPIENTRY
macros for stdcall calling convention
Bugfix: The default OpenGL version in the version
test was set to 1.1
Bugfix: The OpenGL profile and forward-compatibility window parameters were not saved after context creation
+ [X11] Bugfix: Calling glXCreateContextAttribsARB
with an unavailable OpenGL version caused the application to terminate with a BadMatch
Xlib error
[Win32] Removed explicit support for versions of Windows older than Windows XP
diff --git a/src/x11/x11_window.c b/src/x11/x11_window.c
index ae36aa27..ae9e84e7 100644
--- a/src/x11/x11_window.c
+++ b/src/x11/x11_window.c
@@ -45,6 +45,17 @@
#define Button6 6
#define Button7 7
+//========================================================================
+// Error handler for BadMatch errors when requesting context with
+// unavailable OpenGL versions using the GLX_ARB_create_context extension
+//========================================================================
+
+static int errorHandler(Display *display, XErrorEvent* event)
+{
+ return 0;
+}
+
+
//========================================================================
// Checks whether the event is a MapNotify for the specified window
//========================================================================
@@ -580,12 +591,21 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
setGLXattrib(attribs, index, None, None);
+ // This is the only place we set an Xlib error handler, and we only do
+ // it because glXCreateContextAttribsARB generates a BadMatch error if
+ // the requested OpenGL version is unavailable (instead of a civilized
+ // response like returning NULL)
+ XSetErrorHandler(errorHandler);
+
window->GLX.context =
window->GLX.CreateContextAttribsARB(_glfwLibrary.X11.display,
*fbconfig,
share,
True,
attribs);
+
+ // We are done, so unset the error handler again (see above)
+ XSetErrorHandler(NULL);
}
else
{