ui: Bug fix: ScreenSizeFullscreen before Run crashes on Linux

This commit is contained in:
Hajime Hoshi 2018-12-19 01:17:59 +09:00
parent 6ef5cc5857
commit db4395d71b

View File

@ -41,6 +41,8 @@ type userInterface struct {
windowWidth int
height int
initMonitor *glfw.Monitor
initFullscreenWidth int
initFullscreenHeight int
scale float64
fullscreenScale float64
@ -99,6 +101,10 @@ func initialize() error {
// TODO: Fix this hack. currentMonitorImpl now requires u.window on POSIX.
currentUI.window = w
currentUI.initMonitor = currentUI.currentMonitorImpl()
v := currentUI.initMonitor.GetVideoMode()
s := glfwScale()
currentUI.initFullscreenWidth = int(float64(v.Width) / s)
currentUI.initFullscreenHeight = int(float64(v.Height) / s)
currentUI.window.Destroy()
currentUI.window = nil
@ -236,18 +242,17 @@ func (u *userInterface) setInitIconImages(iconImages []image.Image) {
func ScreenSizeInFullscreen() (int, int) {
u := currentUI
if !u.isRunning() {
return u.initFullscreenWidth, u.initFullscreenHeight
}
var v *glfw.VidMode
s := 0.0
if u.isRunning() {
_ = mainthread.Run(func() error {
v = u.currentMonitor().GetVideoMode()
s = glfwScale()
return nil
})
} else {
v = currentUI.initMonitor.GetVideoMode()
s = glfwScale()
}
return int(float64(v.Width) / s), int(float64(v.Height) / s)
}