From f09cf7fa473274e4b47b2e84d23693279c333440 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 18 Apr 2021 01:03:06 +0900 Subject: [PATCH] internal/uidriver/glfw: Bug fix: Crash at Iconify This is the same reason as Maximize. Updates #1576 --- internal/uidriver/glfw/ui.go | 14 +++++++++++++- internal/uidriver/glfw/window.go | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/uidriver/glfw/ui.go b/internal/uidriver/glfw/ui.go index 6cdddbd70..79356a7b2 100644 --- a/internal/uidriver/glfw/ui.go +++ b/internal/uidriver/glfw/ui.go @@ -1322,7 +1322,7 @@ func (u *UserInterface) Window() driver.Window { } func (u *UserInterface) maximize() { - // Maximizing invokes the SetSize callback but the callback must not be called in the game's Update (#1576). + // Maximize invokes the SetSize callback but the callback must not be called in the game's Update (#1576). if u.unregisterWindowSetSizeCallback() { defer u.registerWindowSetSizeCallback() } @@ -1333,6 +1333,18 @@ func (u *UserInterface) maximize() { u.setWindowSize(w, h, u.isFullscreen()) } +func (u *UserInterface) iconify() { + // Iconify invokes the SetSize callback but the callback must not be called in the game's Update (#1576). + if u.unregisterWindowSetSizeCallback() { + defer u.registerWindowSetSizeCallback() + } + u.window.Iconify() + + // Call setWindowSize explicitly in order to update the rendering since the callback is unregistered now. + w, h := u.window.GetSize() + u.setWindowSize(w, h, u.isFullscreen()) +} + func (u *UserInterface) restore() { // Restore invokes the SetSize callback but the callback must not be called in the game's Update (#1576). if u.unregisterWindowSetSizeCallback() { diff --git a/internal/uidriver/glfw/window.go b/internal/uidriver/glfw/window.go index ee8df03cb..c53575f11 100644 --- a/internal/uidriver/glfw/window.go +++ b/internal/uidriver/glfw/window.go @@ -159,7 +159,7 @@ func (w *window) Minimize() { return } _ = w.ui.t.Call(func() error { - w.ui.window.Iconify() + w.ui.iconify() return nil }) }