From f756be3d22c1826b4504c17b0625075ba0fcc86c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 3 Apr 2022 19:32:01 +0900 Subject: [PATCH] internal/devicescale: bug fix: glfw.Monitor.GetContentScale might return 0 Retrying to call GetContentScale solved this. Closes #2051 --- internal/devicescale/impl_desktop.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/devicescale/impl_desktop.go b/internal/devicescale/impl_desktop.go index 8c7db22b0..6f26fe957 100644 --- a/internal/devicescale/impl_desktop.go +++ b/internal/devicescale/impl_desktop.go @@ -35,6 +35,13 @@ func monitorAt(x, y int) *glfw.Monitor { } func impl(x, y int) float64 { - sx, _ := monitorAt(x, y).GetContentScale() - return float64(sx) + // Keep calling GetContentScale until the returned scale is 0 (#2051). + // Retry this at most 5 times to avoid an inifinite loop. + for i := 0; i < 5; i++ { + sx, _ := monitorAt(x, y).GetContentScale() + if sx != 0 { + return float64(sx) + } + } + return 1 }