From f591ca3d2b3358bb886e4243b327bbc30948af45 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 15 Jul 2017 21:43:33 +0900 Subject: [PATCH] ui: Bug fix: SetFullscreen didn't work without Run --- internal/ui/ui_glfw.go | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 860b01633..c03ca64d7 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -44,6 +44,7 @@ type userInterface struct { sizeChanged bool origPosX int origPosY int + initFullscreen bool m sync.Mutex } @@ -155,14 +156,16 @@ func SetScreenScale(scale float64) bool { } func SetFullscreen(fullscreen bool) { - // This can be called before Run: change the state asyncly. - go func() { - _ = currentUI.runOnMainThread(func() error { - u := currentUI - u.setScreenSize(u.width, u.height, u.scale, fullscreen) - return nil - }) - }() + u := currentUI + if !u.isRunning() { + u.initFullscreen = fullscreen + return + } + _ = u.runOnMainThread(func() error { + u := currentUI + u.setScreenSize(u.width, u.height, u.scale, fullscreen) + return nil + }) } func ScreenScale() float64 { @@ -247,6 +250,9 @@ func Run(width, height int, scale float64, title string, g GraphicsContext) erro if err := u.runOnMainThread(func() error { m := glfw.GetPrimaryMonitor() v := m.GetVideoMode() + + // The game is in window mode (not fullscreen mode) at the first state. + // Don't refer u.initFullscreen here to avoid some GLFW problems. if !u.setScreenSize(width, height, scale, false) { return errors.New("ui: Fail to set the screen size") } @@ -319,6 +325,15 @@ func (u *userInterface) update(g GraphicsContext) error { return &RegularTermination{} } + _ = u.runOnMainThread(func() error { + if u.initFullscreen { + u := currentUI + u.setScreenSize(u.width, u.height, u.scale, true) + u.initFullscreen = false + } + return nil + }) + actualScale := 0.0 sizeChanged := false _ = u.runOnMainThread(func() error {