瀏覽代碼

Check success of MakeCurrent before updating TLS

Fixes #706.
Camilla Berglund 9 年之前
父節點
當前提交
2826f3d42f
共有 3 個文件被更改,包括 54 次插入15 次删除
  1. 20 8
      src/egl_context.c
  2. 16 4
      src/glx_context.c
  3. 18 3
      src/wgl_context.c

+ 20 - 8
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);

+ 16 - 4
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);
 }

+ 18 - 3
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)