From acd317bf91f6bab242572fe8beeb2aedfe41c1e4 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 18 Nov 2023 20:01:19 +0900 Subject: [PATCH] internal/ui: bug fix: wrong for-loop condition Closes #2847 --- internal/ui/ui_glfw.go | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 8907a6b48..65cefeb47 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -1358,20 +1358,32 @@ func (u *UserInterface) update() (float64, float64, error) { } } - // In the initial state on macOS, the window is not shown (#2620). - visible, err := u.window.GetAttrib(glfw.Visible) - if err != nil { - return 0, 0, err - } - focused, err := u.window.GetAttrib(glfw.Focused) - if err != nil { - return 0, 0, err - } - shouldClose, err := u.window.ShouldClose() - if err != nil { - return 0, 0, err - } - for visible != 0 && !u.isRunnableOnUnfocused() && focused == 0 && !shouldClose { + for !u.isRunnableOnUnfocused() { + // In the initial state on macOS, the window is not shown (#2620). + visible, err := u.window.GetAttrib(glfw.Visible) + if err != nil { + return 0, 0, err + } + if visible == glfw.False { + break + } + + focused, err := u.window.GetAttrib(glfw.Focused) + if err != nil { + return 0, 0, err + } + if focused != glfw.False { + break + } + + shouldClose, err := u.window.ShouldClose() + if err != nil { + return 0, 0, err + } + if shouldClose { + break + } + if err := hook.SuspendAudio(); err != nil { return 0, 0, err } @@ -1381,6 +1393,7 @@ func (u *UserInterface) update() (float64, float64, error) { return 0, 0, err } } + if err := hook.ResumeAudio(); err != nil { return 0, 0, err }