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

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