From cca9008db29f697dd3dc6d23dc149c1b3d29aa00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 4 Oct 2021 20:32:32 +0200 Subject: [PATCH] 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. --- README.md | 1 + src/egl_context.c | 4 ++-- src/glx_context.c | 4 ++-- src/nsgl_context.m | 2 +- src/osmesa_context.c | 14 +++++++++++++- src/wgl_context.c | 2 +- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0e075ee3..ea83adac 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,7 @@ information on what to include when reporting a bug. - Bugfix: Buffers were swapped at creation on single-buffered windows (#1873) - Bugfix: Gamepad mapping updates could spam `GLFW_INVALID_VALUE` due to incompatible controllers sharing hardware ID (#1763) + - Bugfix: Native access functions for context handles did not check that the API matched - [Win32] Added the `GLFW_WIN32_KEYBOARD_MENU` window hint for enabling access to the window menu - [Win32] Added a version info resource to the GLFW DLL diff --git a/src/egl_context.c b/src/egl_context.c index 264b233a..d25c5bd1 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -821,7 +821,7 @@ GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* handle) _GLFWwindow* window = (_GLFWwindow*) handle; _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); return EGL_NO_CONTEXT; @@ -835,7 +835,7 @@ GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* handle) _GLFWwindow* window = (_GLFWwindow*) handle; _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); return EGL_NO_SURFACE; diff --git a/src/glx_context.c b/src/glx_context.c index 7207cd55..1abc1797 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -674,7 +674,7 @@ GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* handle) _GLFWwindow* window = (_GLFWwindow*) handle; _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); return NULL; @@ -688,7 +688,7 @@ GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* handle) _GLFWwindow* window = (_GLFWwindow*) handle; _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); return None; diff --git a/src/nsgl_context.m b/src/nsgl_context.m index 3f73f7a6..940ee848 100644 --- a/src/nsgl_context.m +++ b/src/nsgl_context.m @@ -358,7 +358,7 @@ GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle) _GLFWwindow* window = (_GLFWwindow*) handle; _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); return nil; diff --git a/src/osmesa_context.c b/src/osmesa_context.c index 74a9291b..da39ffcf 100644 --- a/src/osmesa_context.c +++ b/src/osmesa_context.c @@ -302,6 +302,12 @@ GLFWAPI int glfwGetOSMesaColorBuffer(GLFWwindow* handle, int* width, _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, &mesaWidth, &mesaHeight, &mesaFormat, &mesaBuffer)) @@ -335,6 +341,12 @@ GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* handle, _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, &mesaWidth, &mesaHeight, &mesaBytes, &mesaBuffer)) @@ -361,7 +373,7 @@ GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow* handle) _GLFWwindow* window = (_GLFWwindow*) handle; _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); return NULL; diff --git a/src/wgl_context.c b/src/wgl_context.c index 62055847..2c452661 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -786,7 +786,7 @@ GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* handle) _GLFWwindow* window = (_GLFWwindow*) handle; _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); return NULL;