Skip to content

Commit

Permalink
internal/devicescale: bug fix: glfw.Monitor.GetContentScale might ret…
Browse files Browse the repository at this point in the history
…urn 0

Retrying to call GetContentScale solved this.

Closes hajimehoshi#2051
  • Loading branch information
hajimehoshi committed Apr 3, 2022
1 parent 6f87e49 commit ca6f4fc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/devicescale/impl_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit ca6f4fc

Please sign in to comment.