mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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).
|
||||
// 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
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user