mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +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.
|
||||
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())
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ func (w *window) Maximize() {
|
||||
return
|
||||
}
|
||||
_ = w.ui.t.Call(func() error {
|
||||
w.ui.window.Maximize()
|
||||
w.ui.maximize()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user