From 2826f3d42fc9d12b4336145ff647730e9e692945 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 15 Feb 2016 15:34:33 +0100 Subject: [PATCH] Check success of MakeCurrent before updating TLS Fixes #706. --- src/egl_context.c | 28 ++++++++++++++++++++-------- src/glx_context.c | 20 ++++++++++++++++---- src/wgl_context.c | 21 ++++++++++++++++++--- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/egl_context.c b/src/egl_context.c index ea970708..827ccbfd 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -583,17 +583,29 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) { if (window) { - eglMakeCurrent(_glfw.egl.display, - window->context.egl.surface, - window->context.egl.surface, - window->context.egl.handle); + if (!eglMakeCurrent(_glfw.egl.display, + window->context.egl.surface, + window->context.egl.surface, + window->context.egl.handle)) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "EGL: Failed to make context current: %s", + getErrorString(eglGetError())); + return; + } } else { - eglMakeCurrent(_glfw.egl.display, - EGL_NO_SURFACE, - EGL_NO_SURFACE, - EGL_NO_CONTEXT); + if (!eglMakeCurrent(_glfw.egl.display, + EGL_NO_SURFACE, + EGL_NO_SURFACE, + EGL_NO_CONTEXT)) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "EGL: Failed to clear current context: %s", + getErrorString(eglGetError())); + return; + } } _glfwPlatformSetCurrentContext(window); diff --git a/src/glx_context.c b/src/glx_context.c index 84c0c701..22ec7e10 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -545,12 +545,24 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) { if (window) { - glXMakeCurrent(_glfw.x11.display, - window->context.glx.window, - window->context.glx.handle); + if (!glXMakeCurrent(_glfw.x11.display, + window->context.glx.window, + window->context.glx.handle)) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "GLX: Failed to make context current"); + return; + } } else - glXMakeCurrent(_glfw.x11.display, None, NULL); + { + if (!glXMakeCurrent(_glfw.x11.display, None, NULL)) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "GLX: Failed to clear current context"); + return; + } + } _glfwPlatformSetCurrentContext(window); } diff --git a/src/wgl_context.c b/src/wgl_context.c index 55138e70..afc85bab 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -594,11 +594,26 @@ int _glfwAnalyzeContextWGL(_GLFWwindow* window, void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) { if (window) - wglMakeCurrent(window->context.wgl.dc, window->context.wgl.handle); + { + if (wglMakeCurrent(window->context.wgl.dc, window->context.wgl.handle)) + _glfwPlatformSetCurrentContext(window); + else + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "WGL: Failed to make context current"); + _glfwPlatformSetCurrentContext(NULL); + } + } else - wglMakeCurrent(NULL, NULL); + { + if (!wglMakeCurrent(NULL, NULL)) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "WGL: Failed to clear current context"); + } - _glfwPlatformSetCurrentContext(window); + _glfwPlatformSetCurrentContext(NULL); + } } void _glfwPlatformSwapBuffers(_GLFWwindow* window)