浏览代码

Win32: Fix bad content scale on monitor disconnect

The monitor handle could have become invalid just before the call to
GetDpiForMonitor.  It was possible for both window and monitor content
scale queries.

This ensures both that an appropriate error is emitted and that the
retrieved values are zero on error.

Fixes #1615

(cherry picked from commit fbfd7e65c842c7909b11747f0641364593304f1a)
Camilla Löwy 3 年之前
父节点
当前提交
e10def6de7
共有 3 个文件被更改,包括 16 次插入1 次删除
  1. 1 0
      CONTRIBUTORS.md
  2. 3 0
      README.md
  3. 12 1
      src/win32_monitor.c

+ 1 - 0
CONTRIBUTORS.md

@@ -62,6 +62,7 @@ video tutorials.
  - Mário Freitas
  - Mário Freitas
  - GeO4d
  - GeO4d
  - Marcus Geelnard
  - Marcus Geelnard
+ - ghuser404
  - Charles Giessen
  - Charles Giessen
  - Ryan C. Gordon
  - Ryan C. Gordon
  - Stephen Gowen
  - Stephen Gowen

+ 3 - 0
README.md

@@ -124,6 +124,9 @@ information on what to include when reporting a bug.
 ## Changelog
 ## Changelog
 
 
  - Bugfix: Joysticks connected before init did not get gamepad mappings (#1996)
  - Bugfix: Joysticks connected before init did not get gamepad mappings (#1996)
+ - [Win32] Bugfix: Content scale queries could fail silently (#1615)
+ - [Win32] Bugfix: Content scales could have garbage values if monitor was recently
+   disconnected (#1615)
  - [Cocoa] Bugfix: A dependency on an external constant caused crashes on macOS
  - [Cocoa] Bugfix: A dependency on an external constant caused crashes on macOS
    11 and earlier (#1985,#1994)
    11 and earlier (#1985,#1994)
  - [X11] Bugfix: Icon pixel format conversion worked only by accident, relying on
  - [X11] Bugfix: Icon pixel format conversion worked only by accident, relying on

+ 12 - 1
src/win32_monitor.c

@@ -318,8 +318,19 @@ void _glfwGetMonitorContentScaleWin32(HMONITOR handle, float* xscale, float* ysc
 {
 {
     UINT xdpi, ydpi;
     UINT xdpi, ydpi;
 
 
+    if (xscale)
+        *xscale = 0.f;
+    if (yscale)
+        *yscale = 0.f;
+
     if (IsWindows8Point1OrGreater())
     if (IsWindows8Point1OrGreater())
-        GetDpiForMonitor(handle, MDT_EFFECTIVE_DPI, &xdpi, &ydpi);
+    {
+        if (GetDpiForMonitor(handle, MDT_EFFECTIVE_DPI, &xdpi, &ydpi) != S_OK)
+        {
+            _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to query monitor DPI");
+            return;
+        }
+    }
     else
     else
     {
     {
         const HDC dc = GetDC(NULL);
         const HDC dc = GetDC(NULL);