internal/graphicscommand: add Terminate

This change reduces a render thread usage in internal/ui.

Updates #2714
This commit is contained in:
Hajime Hoshi 2023-12-27 02:28:53 +09:00
parent 08ae0f4a94
commit 338b8957e8
2 changed files with 7 additions and 3 deletions

View File

@ -39,3 +39,9 @@ func runOnRenderThread(f func(), sync bool) {
// This blocking is expected as double-buffering is used. // This blocking is expected as double-buffering is used.
theRenderThread.CallAsync(f) 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() {})
}

View File

@ -1397,9 +1397,7 @@ func (u *UserInterface) update() (float64, float64, error) {
func (u *UserInterface) loopGame() (ferr error) { func (u *UserInterface) loopGame() (ferr error) {
defer func() { defer func() {
// Post a task to the render thread to ensure all the queued functions are executed. graphicscommand.Terminate()
// glfw.Terminate will remove the context and any graphics calls after that will be invalidated.
u.renderThread.Call(func() {})
u.mainThread.Call(func() { u.mainThread.Call(func() {
if err := glfw.Terminate(); err != nil { if err := glfw.Terminate(); err != nil {
ferr = err ferr = err