internal/glfw: do not panic for an error at Monitor.GetContentScale

Updates #2488
This commit is contained in:
Hajime Hoshi 2022-12-08 13:39:15 +09:00
parent 8a95b1d85c
commit 1f741fa007
3 changed files with 13 additions and 11 deletions

View File

@ -37,10 +37,15 @@ func impl(x, y int) float64 {
// 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)
// An error can happen e.g. when entering a screensaver on Windows (#2488).
sx, _, err := monitorAt(x, y).GetContentScale()
if err != nil {
continue
}
if sx == 0 {
continue
}
return float64(sx)
}
return 1
}

View File

@ -70,8 +70,9 @@ type Monitor struct {
m *glfw.Monitor
}
func (m *Monitor) GetContentScale() (float32, float32) {
return m.m.GetContentScale()
func (m *Monitor) GetContentScale() (float32, float32, error) {
x, y := m.m.GetContentScale()
return x, y, nil
}
func (m *Monitor) GetPos() (x, y int) {

View File

@ -34,12 +34,8 @@ func CreateStandardCursor(shape StandardCursor) *Cursor {
type Monitor glfwwin.Monitor
func (m *Monitor) GetContentScale() (float32, float32) {
sx, sy, err := (*glfwwin.Monitor)(m).GetContentScale()
if err != nil {
panic(err)
}
return sx, sy
func (m *Monitor) GetContentScale() (float32, float32, error) {
return (*glfwwin.Monitor)(m).GetContentScale()
}
func (m *Monitor) GetPos() (int, int) {