mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
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:
parent
2661c769ef
commit
ab8477a21a
@ -693,8 +693,8 @@ func (u *UserInterface) createWindow() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// unregisterWindowSetSizeCallback must be called from the main thread.
|
// unregisterWindowSetSizeCallback must be called from the main thread.
|
||||||
func (u *UserInterface) unregisterWindowSetSizeCallback() {
|
func (u *UserInterface) unregisterWindowSetSizeCallback() bool {
|
||||||
u.window.SetSizeCallback(nil)
|
return u.window.SetSizeCallback(nil) != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// registerWindowSetSizeCallback must be called from the main thread.
|
// 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.
|
// Do not fire the callback of SetSize. This callback can be invoked by SetMonitor or SetSize.
|
||||||
// ForceUpdate is called from the callback.
|
// ForceUpdate is called from the callback.
|
||||||
// While setWindowSize can be called from Update, calling ForceUpdate inside Update is illegal (#1505).
|
// While setWindowSize can be called from Update, calling ForceUpdate inside Update is illegal (#1505).
|
||||||
u.unregisterWindowSetSizeCallback()
|
if u.unregisterWindowSetSizeCallback() {
|
||||||
defer u.registerWindowSetSizeCallback()
|
defer u.registerWindowSetSizeCallback()
|
||||||
|
}
|
||||||
|
|
||||||
var windowRecreated bool
|
var windowRecreated bool
|
||||||
|
|
||||||
@ -1295,3 +1296,15 @@ func (u *UserInterface) Input() driver.Input {
|
|||||||
func (u *UserInterface) Window() driver.Window {
|
func (u *UserInterface) Window() driver.Window {
|
||||||
return &u.iwindow
|
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())
|
||||||
|
}
|
||||||
|
@ -136,7 +136,7 @@ func (w *window) Maximize() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = w.ui.t.Call(func() error {
|
_ = w.ui.t.Call(func() error {
|
||||||
w.ui.window.Maximize()
|
w.ui.maximize()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user