mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
internal/ui: bug fix: need nil check at dipFromGLFWMonitorPixel
Updates #1878
This commit is contained in:
parent
4da4b49ce6
commit
a65a45586f
@ -28,12 +28,12 @@ type Monitor struct {
|
||||
m *glfw.Monitor
|
||||
videoMode *glfw.VidMode
|
||||
|
||||
id int
|
||||
name string
|
||||
x int
|
||||
y int
|
||||
contentScale float64
|
||||
videoModeScale float64
|
||||
id int
|
||||
name string
|
||||
x int
|
||||
y int
|
||||
contentScale float64
|
||||
videoModeScale_ float64
|
||||
}
|
||||
|
||||
// Name returns the monitor's name.
|
||||
@ -50,6 +50,15 @@ func (m *Monitor) deviceScaleFactor() float64 {
|
||||
return m.contentScale
|
||||
}
|
||||
|
||||
func (m *Monitor) videoModeScale() float64 {
|
||||
// It is rare, but monitor can be nil when glfw.GetPrimaryMonitor returns nil.
|
||||
// In this case, return 1 as a tentative scale (#1878).
|
||||
if m == nil {
|
||||
return 1
|
||||
}
|
||||
return m.videoModeScale_
|
||||
}
|
||||
|
||||
type monitors struct {
|
||||
// monitors is the monitor list cache for desktop glfw compile targets.
|
||||
// populated by 'updateMonitors' which is called on init and every
|
||||
@ -134,14 +143,14 @@ func (m *monitors) update() {
|
||||
}
|
||||
|
||||
newMonitors = append(newMonitors, &Monitor{
|
||||
m: m,
|
||||
videoMode: m.GetVideoMode(),
|
||||
id: i,
|
||||
name: m.GetName(),
|
||||
x: x,
|
||||
y: y,
|
||||
contentScale: contentScale,
|
||||
videoModeScale: videoModeScale(m),
|
||||
m: m,
|
||||
videoMode: m.GetVideoMode(),
|
||||
id: i,
|
||||
name: m.GetName(),
|
||||
x: x,
|
||||
y: y,
|
||||
contentScale: contentScale,
|
||||
videoModeScale_: videoModeScale(m),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ func videoModeScale(m *glfw.Monitor) float64 {
|
||||
}
|
||||
|
||||
func dipFromGLFWMonitorPixel(x float64, monitor *Monitor) float64 {
|
||||
return x / (monitor.videoModeScale * monitor.deviceScaleFactor())
|
||||
return x / (monitor.videoModeScale() * monitor.deviceScaleFactor())
|
||||
}
|
||||
|
||||
func dipFromGLFWPixel(x float64, monitor *Monitor) float64 {
|
||||
|
Loading…
Reference in New Issue
Block a user