Quellcode durchsuchen

Viewports: default to first monitor is viewport is outside bounds. (#8393, #8385)

Before the assert was introduced in d66f4e589 the viewport would be eventually clamped with ClampWindowPos using g.FallbackMonitor, but code would run temporarly with DpiScale=0.
Gabriel Rodriguez vor 6 Monaten
Ursprung
Commit
95c4111783
2 geänderte Dateien mit 8 neuen und 2 gelöschten Zeilen
  1. 5 0
      docs/CHANGELOG.txt
  2. 3 2
      imgui.cpp

+ 5 - 0
docs/CHANGELOG.txt

@@ -83,6 +83,11 @@ Other changes:
 - Backends: WebGPU: Fix for DAWN API rename WGPUProgrammableStageDescriptor -> WGPUComputeState.
   [@PhantomCloak] (#8369)
 
+Docking+Viewports Branch:
+
+- Viewports: fixed an assert when a window load settings with a position outside
+  monitor bounds, when there are multiple monitors. (#8393, #8385) [@gaborodriguez]
+
 
 -----------------------------------------------------------------------
  VERSION 1.91.8 (Released 2025-01-31)

+ 3 - 2
imgui.cpp

@@ -16536,13 +16536,14 @@ static int ImGui::FindPlatformMonitorForRect(const ImRect& rect)
     ImGuiContext& g = *GImGui;
 
     const int monitor_count = g.PlatformIO.Monitors.Size;
+    IM_ASSERT(monitor_count > 0);
     if (monitor_count <= 1)
-        return monitor_count - 1;
+        return 0;
 
     // Use a minimum threshold of 1.0f so a zero-sized rect won't false positive, and will still find the correct monitor given its position.
     // This is necessary for tooltips which always resize down to zero at first.
     const float surface_threshold = ImMax(rect.GetWidth() * rect.GetHeight() * 0.5f, 1.0f);
-    int best_monitor_n = -1;
+    int best_monitor_n = 0; // Default to the first monitor as fallback
     float best_monitor_surface = 0.001f;
 
     for (int monitor_n = 0; monitor_n < g.PlatformIO.Monitors.Size && best_monitor_surface < surface_threshold; monitor_n++)