internal/uidriver/glfw: Bug fix: Crash on Maximize

At least on macOS, Maximize invokes the SetSize callback in the game's
Update. This change fixes this issue by unregisting the callback
temporarily like what #1505 did.

Closes #1576
This commit is contained in:
Hajime Hoshi 2021-04-17 23:57:17 +09:00
parent 2661c769ef
commit ab8477a21a
2 changed files with 18 additions and 5 deletions

View File

@ -693,8 +693,8 @@ func (u *UserInterface) createWindow() error {
}
// unregisterWindowSetSizeCallback must be called from the main thread.
func (u *UserInterface) unregisterWindowSetSizeCallback() {
u.window.SetSizeCallback(nil)
func (u *UserInterface) unregisterWindowSetSizeCallback() bool {
return u.window.SetSizeCallback(nil) != nil
}
// registerWindowSetSizeCallback must be called from the main thread.
@ -1075,8 +1075,9 @@ func (u *UserInterface) setWindowSize(width, height int, fullscreen bool) {
// Do not fire the callback of SetSize. This callback can be invoked by SetMonitor or SetSize.
// ForceUpdate is called from the callback.
// While setWindowSize can be called from Update, calling ForceUpdate inside Update is illegal (#1505).
u.unregisterWindowSetSizeCallback()
defer u.registerWindowSetSizeCallback()
if u.unregisterWindowSetSizeCallback() {
defer u.registerWindowSetSizeCallback()
}
var windowRecreated bool
@ -1295,3 +1296,15 @@ func (u *UserInterface) Input() driver.Input {
func (u *UserInterface) Window() driver.Window {
return &u.iwindow
}
func (u *UserInterface) maximize() {
// Maximizing invokes the SetSize callback but the callback must not be called in Update.
if u.unregisterWindowSetSizeCallback() {
defer u.registerWindowSetSizeCallback()
}
u.window.Maximize()
// 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())
}

View File

@ -136,7 +136,7 @@ func (w *window) Maximize() {
return
}
_ = w.ui.t.Call(func() error {
w.ui.window.Maximize()
w.ui.maximize()
return nil
})
}