From db4395d71b7e669d8a8012b65c52c5aec7f2e5dc Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 19 Dec 2018 01:17:59 +0900 Subject: [PATCH] ui: Bug fix: ScreenSizeFullscreen before Run crashes on Linux --- internal/ui/ui_glfw.go | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 175f17107..a1315b5c7 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -35,12 +35,14 @@ import ( ) type userInterface struct { - title string - window *glfw.Window - width int - windowWidth int - height int - initMonitor *glfw.Monitor + title string + window *glfw.Window + width int + 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() + _ = mainthread.Run(func() error { + v = u.currentMonitor().GetVideoMode() s = glfwScale() - } + return nil + }) return int(float64(v.Width) / s), int(float64(v.Height) / s) }