From 00e86d4b733103a23278fe53ce58a0d14dd47d32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 30 Jan 2024 18:21:33 +0100 Subject: [PATCH] WGL: Fix pixel format count in a Parallels VM In a Parallels VM wglGetPixelFormatAttribivARB returns fewer pixel formats than DescribePixelFormat. This broke context creation on Windows in Parallels since the changes in 2c0f34b60f7c7a07183ed71754b0156ece3b6c1b. The previous version of the code worked accidentally. This adds a workaround by iterating through the minimum of both counts. It should have no effect when running on conforming implementations. Tested on Parallels by @ dougbinks. Closes #2191 Fixes #2406 Fixes #2467 --- CONTRIBUTORS.md | 2 ++ src/wgl_context.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 570b7707..6f426cdd 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -47,6 +47,7 @@ video tutorials. - Bailey Cosier - Noel Cower - CuriouserThing + - Bill Currie - Jason Daly - danhambleton - Jarrod Davis @@ -166,6 +167,7 @@ video tutorials. - Pascal Muetschard - James Murphy - Julian Møller + - NateIsStalling - ndogxj - F. Nedelec - n3rdopolis diff --git a/src/wgl_context.c b/src/wgl_context.c index 65d758af..8a23ffc4 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -115,6 +115,23 @@ static int choosePixelFormatWGL(_GLFWwindow* window, if (_glfw.wgl.EXT_colorspace) ADD_ATTRIB(WGL_COLORSPACE_EXT); } + + // NOTE: In a Parallels VM WGL_ARB_pixel_format returns fewer pixel formats than + // DescribePixelFormat, violating the guarantees of the extension spec + // HACK: Iterate through the minimum of both counts + + const int attrib = WGL_NUMBER_PIXEL_FORMATS_ARB; + int extensionCount; + + if (!wglGetPixelFormatAttribivARB(window->context.wgl.dc, + 1, 0, 1, &attrib, &extensionCount)) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "WGL: Failed to retrieve pixel format attribute"); + return 0; + } + + nativeCount = _glfw_min(nativeCount, extensionCount); } usableConfigs = _glfw_calloc(nativeCount, sizeof(_GLFWfbconfig));