From 338b8957e80249585b4efd57d8ad70f1a70b2559 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 27 Dec 2023 02:28:53 +0900 Subject: [PATCH] internal/graphicscommand: add Terminate This change reduces a render thread usage in internal/ui. Updates #2714 --- internal/graphicscommand/thread.go | 6 ++++++ internal/ui/ui_glfw.go | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/graphicscommand/thread.go b/internal/graphicscommand/thread.go index aebb6d3ce..8cafef1b7 100644 --- a/internal/graphicscommand/thread.go +++ b/internal/graphicscommand/thread.go @@ -39,3 +39,9 @@ func runOnRenderThread(f func(), sync bool) { // This blocking is expected as double-buffering is used. theRenderThread.CallAsync(f) } + +func Terminate() { + // Post a task to the render thread to ensure all the queued functions are executed. + // This is necessary especially for GLFW. glfw.Terminate will remove the context and any graphics calls after that will be invalidated. + theRenderThread.Call(func() {}) +} diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index aa0e189eb..2cea80494 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -1397,9 +1397,7 @@ func (u *UserInterface) update() (float64, float64, error) { func (u *UserInterface) loopGame() (ferr error) { defer func() { - // Post a task to the render thread to ensure all the queued functions are executed. - // glfw.Terminate will remove the context and any graphics calls after that will be invalidated. - u.renderThread.Call(func() {}) + graphicscommand.Terminate() u.mainThread.Call(func() { if err := glfw.Terminate(); err != nil { ferr = err