From c88ee0d0ad29ebf1ec85732489101c2bfffe2107 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 18 Apr 2021 21:23:59 +0900 Subject: [PATCH] internal/uidriver/glfw: Bug fix: Unregister SetSize callback when undecorate the window Closes #1586 --- internal/uidriver/glfw/ui.go | 17 +++++++++++++++++ internal/uidriver/glfw/window.go | 8 ++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/internal/uidriver/glfw/ui.go b/internal/uidriver/glfw/ui.go index e013ed3e4..fb80f0565 100644 --- a/internal/uidriver/glfw/ui.go +++ b/internal/uidriver/glfw/ui.go @@ -1362,3 +1362,20 @@ func (u *UserInterface) restore() { w, h := u.window.GetSize() u.setWindowSize(w, h, u.isFullscreen()) } + +func (u *UserInterface) setDecorated(decorated bool) { + // SetAttrib with glfw.Decorated invokes the SetSize callback but the callback must not be called in the game's Update (#1586). + // SetSize callback is invoked in the limited situations like just after restoring from the fullscreen mode. + if u.unregisterWindowSetSizeCallback() { + defer u.registerWindowSetSizeCallback() + } + v := glfw.False + if decorated { + v = glfw.True + } + u.window.SetAttrib(glfw.Decorated, v) + + // Just after restoring from the fullscreen mode, the window's size might be a wrong value on Windows. + // This was the cause to invoke SetSize callback unexpectedly. This sounds like a GLFW's issue, but this is not confirmed. + // As the window size should not be changed, setWindowSize doesn't have to be called anyway. +} diff --git a/internal/uidriver/glfw/window.go b/internal/uidriver/glfw/window.go index 8a3c5d8eb..3b7c49890 100644 --- a/internal/uidriver/glfw/window.go +++ b/internal/uidriver/glfw/window.go @@ -51,14 +51,10 @@ func (w *window) SetDecorated(decorated bool) { return nil } - v := glfw.False - if decorated { - v = glfw.True - } - w.ui.window.SetAttrib(glfw.Decorated, v) + w.ui.setDecorated(decorated) // The title can be lost when the decoration is gone. Recover this. - if v == glfw.True { + if decorated { w.ui.window.SetTitle(w.ui.title) } return nil