Skip to content

Commit 95c4111

Browse files
Gabriel Rodriguezocornut
Gabriel Rodriguez
authored andcommitted
Viewports: default to first monitor is viewport is outside bounds. (ocornut#8393, ocornut#8385)
Before the assert was introduced in d66f4e5 the viewport would be eventually clamped with ClampWindowPos using g.FallbackMonitor, but code would run temporarly with DpiScale=0.
1 parent 71d39a4 commit 95c4111

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

docs/CHANGELOG.txt

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ Other changes:
8383
- Backends: WebGPU: Fix for DAWN API rename WGPUProgrammableStageDescriptor -> WGPUComputeState.
8484
[@PhantomCloak] (#8369)
8585

86+
Docking+Viewports Branch:
87+
88+
- Viewports: fixed an assert when a window load settings with a position outside
89+
monitor bounds, when there are multiple monitors. (#8393, #8385) [@gaborodriguez]
90+
8691

8792
-----------------------------------------------------------------------
8893
VERSION 1.91.8 (Released 2025-01-31)

imgui.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -16536,13 +16536,14 @@ static int ImGui::FindPlatformMonitorForRect(const ImRect& rect)
1653616536
ImGuiContext& g = *GImGui;
1653716537

1653816538
const int monitor_count = g.PlatformIO.Monitors.Size;
16539+
IM_ASSERT(monitor_count > 0);
1653916540
if (monitor_count <= 1)
16540-
return monitor_count - 1;
16541+
return 0;
1654116542

1654216543
// 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.
1654316544
// This is necessary for tooltips which always resize down to zero at first.
1654416545
const float surface_threshold = ImMax(rect.GetWidth() * rect.GetHeight() * 0.5f, 1.0f);
16545-
int best_monitor_n = -1;
16546+
int best_monitor_n = 0; // Default to the first monitor as fallback
1654616547
float best_monitor_surface = 0.001f;
1654716548

1654816549
for (int monitor_n = 0; monitor_n < g.PlatformIO.Monitors.Size && best_monitor_surface < surface_threshold; monitor_n++)

0 commit comments

Comments
 (0)