소스 검색

Make native access functions verify context API

The native access functions for context handles did not verify that the
context had been created with the same API the function was for.

This makes these functions emit GLFW_NO_WINDOW_CONTEXT on API mismatch.

(cherry picked from commit cca9008db29f697dd3dc6d23dc149c1b3d29aa00)
Camilla Löwy 4 년 전
부모
커밋
2d3ce6eaae
6개의 변경된 파일20개의 추가작업 그리고 7개의 파일을 삭제
  1. 1 0
      README.md
  2. 2 2
      src/egl_context.c
  3. 2 2
      src/glx_context.c
  4. 1 1
      src/nsgl_context.m
  5. 13 1
      src/osmesa_context.c
  6. 1 1
      src/wgl_context.c

+ 1 - 0
README.md

@@ -121,6 +121,7 @@ information on what to include when reporting a bug.
  - Bugfix: Buffers were swapped at creation on single-buffered windows (#1873)
  - Bugfix: Buffers were swapped at creation on single-buffered windows (#1873)
  - Bugfix: Gamepad mapping updates could spam `GLFW_INVALID_VALUE` due to
  - Bugfix: Gamepad mapping updates could spam `GLFW_INVALID_VALUE` due to
    incompatible controllers sharing hardware ID (#1763)
    incompatible controllers sharing hardware ID (#1763)
+ - Bugfix: Native access functions for context handles did not check that the API matched
  - [Win32] Bugfix: `USE_MSVC_RUNTIME_LIBRARY_DLL` had no effect on CMake 3.15 or
  - [Win32] Bugfix: `USE_MSVC_RUNTIME_LIBRARY_DLL` had no effect on CMake 3.15 or
    later (#1783,#1796)
    later (#1783,#1796)
  - [Win32] Bugfix: Compilation with LLVM for Windows failed (#1807,#1824,#1874)
  - [Win32] Bugfix: Compilation with LLVM for Windows failed (#1807,#1824,#1874)

+ 2 - 2
src/egl_context.c

@@ -765,7 +765,7 @@ GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* handle)
     _GLFWwindow* window = (_GLFWwindow*) handle;
     _GLFWwindow* window = (_GLFWwindow*) handle;
     _GLFW_REQUIRE_INIT_OR_RETURN(EGL_NO_CONTEXT);
     _GLFW_REQUIRE_INIT_OR_RETURN(EGL_NO_CONTEXT);
 
 
-    if (window->context.client == GLFW_NO_API)
+    if (window->context.client != GLFW_EGL_CONTEXT_API)
     {
     {
         _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
         _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
         return EGL_NO_CONTEXT;
         return EGL_NO_CONTEXT;
@@ -779,7 +779,7 @@ GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* handle)
     _GLFWwindow* window = (_GLFWwindow*) handle;
     _GLFWwindow* window = (_GLFWwindow*) handle;
     _GLFW_REQUIRE_INIT_OR_RETURN(EGL_NO_SURFACE);
     _GLFW_REQUIRE_INIT_OR_RETURN(EGL_NO_SURFACE);
 
 
-    if (window->context.client == GLFW_NO_API)
+    if (window->context.client != GLFW_EGL_CONTEXT_API)
     {
     {
         _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
         _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
         return EGL_NO_SURFACE;
         return EGL_NO_SURFACE;

+ 2 - 2
src/glx_context.c

@@ -674,7 +674,7 @@ GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* handle)
     _GLFWwindow* window = (_GLFWwindow*) handle;
     _GLFWwindow* window = (_GLFWwindow*) handle;
     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
 
 
-    if (window->context.client == GLFW_NO_API)
+    if (window->context.client != GLFW_NATIVE_CONTEXT_API)
     {
     {
         _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
         _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
         return NULL;
         return NULL;
@@ -688,7 +688,7 @@ GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* handle)
     _GLFWwindow* window = (_GLFWwindow*) handle;
     _GLFWwindow* window = (_GLFWwindow*) handle;
     _GLFW_REQUIRE_INIT_OR_RETURN(None);
     _GLFW_REQUIRE_INIT_OR_RETURN(None);
 
 
-    if (window->context.client == GLFW_NO_API)
+    if (window->context.client != GLFW_NATIVE_CONTEXT_API)
     {
     {
         _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
         _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
         return None;
         return None;

+ 1 - 1
src/nsgl_context.m

@@ -365,7 +365,7 @@ GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle)
     _GLFWwindow* window = (_GLFWwindow*) handle;
     _GLFWwindow* window = (_GLFWwindow*) handle;
     _GLFW_REQUIRE_INIT_OR_RETURN(nil);
     _GLFW_REQUIRE_INIT_OR_RETURN(nil);
 
 
-    if (window->context.client == GLFW_NO_API)
+    if (window->context.client != GLFW_NATIVE_CONTEXT_API)
     {
     {
         _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
         _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
         return nil;
         return nil;

+ 13 - 1
src/osmesa_context.c

@@ -302,6 +302,12 @@ GLFWAPI int glfwGetOSMesaColorBuffer(GLFWwindow* handle, int* width,
 
 
     _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE);
     _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE);
 
 
+    if (window->context.client != GLFW_OSMESA_CONTEXT_API)
+    {
+        _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
+        return GLFW_FALSE;
+    }
+
     if (!OSMesaGetColorBuffer(window->context.osmesa.handle,
     if (!OSMesaGetColorBuffer(window->context.osmesa.handle,
                               &mesaWidth, &mesaHeight,
                               &mesaWidth, &mesaHeight,
                               &mesaFormat, &mesaBuffer))
                               &mesaFormat, &mesaBuffer))
@@ -335,6 +341,12 @@ GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* handle,
 
 
     _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE);
     _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE);
 
 
+    if (window->context.client != GLFW_OSMESA_CONTEXT_API)
+    {
+        _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
+        return GLFW_FALSE;
+    }
+
     if (!OSMesaGetDepthBuffer(window->context.osmesa.handle,
     if (!OSMesaGetDepthBuffer(window->context.osmesa.handle,
                               &mesaWidth, &mesaHeight,
                               &mesaWidth, &mesaHeight,
                               &mesaBytes, &mesaBuffer))
                               &mesaBytes, &mesaBuffer))
@@ -361,7 +373,7 @@ GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow* handle)
     _GLFWwindow* window = (_GLFWwindow*) handle;
     _GLFWwindow* window = (_GLFWwindow*) handle;
     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
 
 
-    if (window->context.client == GLFW_NO_API)
+    if (window->context.client != GLFW_OSMESA_CONTEXT_API)
     {
     {
         _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
         _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
         return NULL;
         return NULL;

+ 1 - 1
src/wgl_context.c

@@ -787,7 +787,7 @@ GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* handle)
     _GLFWwindow* window = (_GLFWwindow*) handle;
     _GLFWwindow* window = (_GLFWwindow*) handle;
     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
 
 
-    if (window->context.client == GLFW_NO_API)
+    if (window->context.client != GLFW_NATIVE_CONTEXT_API)
     {
     {
         _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
         _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
         return NULL;
         return NULL;