From 65840c19c4823e537b51bed3298b2818a018a6bf Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 19 Aug 2024 12:18:47 +0200 Subject: [PATCH] Backends: SDL2, SDL3, Win32: don't submit monitor with 0 DpiScale (e.g. accessibility virtual monitor?). to prevent assert. (#7902) I am not too confident on this but I believe pushing this is the fastest way we will get feedback. --- backends/imgui_impl_glfw.cpp | 2 +- backends/imgui_impl_sdl2.cpp | 4 ++++ backends/imgui_impl_sdl3.cpp | 2 ++ backends/imgui_impl_win32.cpp | 2 ++ docs/CHANGELOG.txt | 4 ++-- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp index cc98b49a3..16feb83e6 100644 --- a/backends/imgui_impl_glfw.cpp +++ b/backends/imgui_impl_glfw.cpp @@ -907,7 +907,7 @@ static void ImGui_ImplGlfw_UpdateMonitors() float x_scale, y_scale; glfwGetMonitorContentScale(glfw_monitors[n], &x_scale, &y_scale); if (x_scale == 0.0f) - continue; // Some accessibility applications are declaring fake monitors with a DPI of 0, see (#7902) + continue; // Some accessibility applications are declaring virtual monitors with a DPI of 0, see #7902. monitor.DpiScale = x_scale; #endif monitor.PlatformHandle = (void*)glfw_monitors[n]; // [...] GLFW doc states: "guaranteed to be valid only until the monitor configuration changes" diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp index eeef0c788..4b2df7747 100644 --- a/backends/imgui_impl_sdl2.cpp +++ b/backends/imgui_impl_sdl2.cpp @@ -848,7 +848,11 @@ static void ImGui_ImplSDL2_UpdateMonitors() // DpiScale to cocoa_window.backingScaleFactor here. float dpi = 0.0f; if (!SDL_GetDisplayDPI(n, &dpi, nullptr, nullptr)) + { + if (dpi <= 0.0f) + continue; // Some accessibility applications are declaring virtual monitors with a DPI of 0, see #7902. monitor.DpiScale = dpi / 96.0f; + } #endif monitor.PlatformHandle = (void*)(intptr_t)n; platform_io.Monitors.push_back(monitor); diff --git a/backends/imgui_impl_sdl3.cpp b/backends/imgui_impl_sdl3.cpp index 035ee7b17..0d12e6fac 100644 --- a/backends/imgui_impl_sdl3.cpp +++ b/backends/imgui_impl_sdl3.cpp @@ -806,6 +806,8 @@ static void ImGui_ImplSDL3_UpdateMonitors() // DpiScale to cocoa_window.backingScaleFactor here. monitor.DpiScale = SDL_GetDisplayContentScale(display_id); monitor.PlatformHandle = (void*)(intptr_t)n; + if (monitor.DpiScale <= 0.0f) + continue; // Some accessibility applications are declaring virtual monitors with a DPI of 0, see #7902. platform_io.Monitors.push_back(monitor); } } diff --git a/backends/imgui_impl_win32.cpp b/backends/imgui_impl_win32.cpp index 7470e5e37..816003509 100644 --- a/backends/imgui_impl_win32.cpp +++ b/backends/imgui_impl_win32.cpp @@ -437,6 +437,8 @@ static BOOL CALLBACK ImGui_ImplWin32_UpdateMonitors_EnumFunc(HMONITOR monitor, H imgui_monitor.WorkSize = ImVec2((float)(info.rcWork.right - info.rcWork.left), (float)(info.rcWork.bottom - info.rcWork.top)); imgui_monitor.DpiScale = ImGui_ImplWin32_GetDpiScaleForMonitor(monitor); imgui_monitor.PlatformHandle = (void*)monitor; + if (imgui_monitor.DpiScale <= 0.0f) + return TRUE; // Some accessibility applications are declaring virtual monitors with a DPI of 0, see #7902. ImGuiPlatformIO& io = ImGui::GetPlatformIO(); if (info.dwFlags & MONITORINFOF_PRIMARY) io.Monitors.push_front(imgui_monitor); diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 8f0076efd..6de4295f5 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -56,8 +56,8 @@ Docking+Viewports Branch: - Viewports: added optional platform_io.Platform_GetWindowWorkAreaInsets() hook to allow backends to alter the default per-viewport work-area. (#7823) -- Backends: don't report monitors with DpiScale of 0, which seemed to be reported - for virtual monitors instead by accessibility drivers. (#7902) [@nicolasnoble] +- Backends: don't report monitors with DpiScale of 0, which seemed to be reported for + virtual monitors instead by accessibility drivers. (#7902) [@nicolasnoble, @ocornut] - Backends: SDL2, SDL3: using SDL_HINT_WINDOW_NO_ACTIVATION_WHEN_SHOWN to support the ImGuiViewportFlags_NoFocusOnAppearing flag, instead of using a Win32-specific hack. (#7896) [@RT2Code]