From 16d30858844fc80442e28d7c565eb42291a1b7c3 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 18 Apr 2021 15:22:32 +0900 Subject: [PATCH] internal/uidriver/glfw: Bug fix: FramebufferSize callback was not called when the window size was not changed Closes #1580 --- internal/uidriver/glfw/ui.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/internal/uidriver/glfw/ui.go b/internal/uidriver/glfw/ui.go index 6a74f3681..5b356f290 100644 --- a/internal/uidriver/glfw/ui.go +++ b/internal/uidriver/glfw/ui.go @@ -1032,21 +1032,24 @@ func (u *UserInterface) setWindowSize(width, height int, fullscreen bool) { newW := width newH := height if oldW != newW || oldH != newH { - ch := make(chan struct{}) + ch := make(chan struct{}, 1) u.window.SetFramebufferSizeCallback(func(_ *glfw.Window, _, _ int) { - u.window.SetFramebufferSizeCallback(nil) - close(ch) + ch <- struct{}{} }) u.window.SetSize(newW, newH) - event: - for { - glfw.PollEvents() - select { - case <-ch: - break event - default: + if w, h := u.window.GetSize(); w != oldW || h != oldH { + event: + for { + glfw.PollEvents() + select { + case <-ch: + break event + default: + } } } + u.window.SetFramebufferSizeCallback(nil) + close(ch) } // Window title might be lost on macOS after coming back from fullscreen.