mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/glfw: do not panic for an error at Monitor.GetContentScale
Updates #2488
This commit is contained in:
parent
8a95b1d85c
commit
1f741fa007
@ -37,10 +37,15 @@ func impl(x, y int) float64 {
|
|||||||
// Keep calling GetContentScale until the returned scale is 0 (#2051).
|
// Keep calling GetContentScale until the returned scale is 0 (#2051).
|
||||||
// Retry this at most 5 times to avoid an inifinite loop.
|
// Retry this at most 5 times to avoid an inifinite loop.
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
sx, _ := monitorAt(x, y).GetContentScale()
|
// An error can happen e.g. when entering a screensaver on Windows (#2488).
|
||||||
if sx != 0 {
|
sx, _, err := monitorAt(x, y).GetContentScale()
|
||||||
return float64(sx)
|
if err != nil {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
if sx == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return float64(sx)
|
||||||
}
|
}
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
@ -70,8 +70,9 @@ type Monitor struct {
|
|||||||
m *glfw.Monitor
|
m *glfw.Monitor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Monitor) GetContentScale() (float32, float32) {
|
func (m *Monitor) GetContentScale() (float32, float32, error) {
|
||||||
return m.m.GetContentScale()
|
x, y := m.m.GetContentScale()
|
||||||
|
return x, y, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Monitor) GetPos() (x, y int) {
|
func (m *Monitor) GetPos() (x, y int) {
|
||||||
|
@ -34,12 +34,8 @@ func CreateStandardCursor(shape StandardCursor) *Cursor {
|
|||||||
|
|
||||||
type Monitor glfwwin.Monitor
|
type Monitor glfwwin.Monitor
|
||||||
|
|
||||||
func (m *Monitor) GetContentScale() (float32, float32) {
|
func (m *Monitor) GetContentScale() (float32, float32, error) {
|
||||||
sx, sy, err := (*glfwwin.Monitor)(m).GetContentScale()
|
return (*glfwwin.Monitor)(m).GetContentScale()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return sx, sy
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Monitor) GetPos() (int, int) {
|
func (m *Monitor) GetPos() (int, int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user