From f843d533335db275e0b014311cd7163a2a003b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 8 Apr 2022 18:22:39 +0200 Subject: [PATCH] Fix glfwMakeContextCurrent using uninitialized TLS Issue reported by danhambleton on the GLFW forum: https://discourse.glfw.org/t/posix-thread-local-storage-tls-error-when-making-context-current/2034 --- CONTRIBUTORS.md | 1 + README.md | 1 + src/context.c | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c93c187e..030abf7c 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -44,6 +44,7 @@ video tutorials. - Noel Cower - CuriouserThing - Jason Daly + - danhambleton - Jarrod Davis - Olivier Delannoy - Paul R. Deppe diff --git a/README.md b/README.md index 334277ed..b49a8a0d 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,7 @@ information on what to include when reporting a bug. - 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 + - Bugfix: `glfwMakeContextCurrent` would access TLS slot before initialization - [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/context.c b/src/context.c index f6629f55..7e0449b4 100644 --- a/src/context.c +++ b/src/context.c @@ -609,10 +609,12 @@ GLFWbool _glfwStringInExtensionString(const char* string, const char* extensions GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; - _GLFWwindow* previous = _glfwPlatformGetTls(&_glfw.contextSlot); + _GLFWwindow* previous; _GLFW_REQUIRE_INIT(); + previous = _glfwPlatformGetTls(&_glfw.contextSlot); + if (window && window->context.client == GLFW_NO_API) { _glfwInputError(GLFW_NO_WINDOW_CONTEXT,