From 3d385ef0aa9ec5dabb41076c79e1290c15da32a0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 15 Jul 2024 22:07:04 +0900 Subject: [PATCH] internal/ui: refactoring: call initOnMainThread on the main thread explicitly Closes #3042 --- internal/ui/run.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/ui/run.go b/internal/ui/run.go index 0596bf999..acca963df 100644 --- a/internal/ui/run.go +++ b/internal/ui/run.go @@ -45,10 +45,6 @@ func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error { u.context = newContext(game) - if err := u.initOnMainThread(options); err != nil { - return err - } - ctx, cancel := stdcontext.WithCancel(stdcontext.Background()) defer cancel() @@ -64,6 +60,17 @@ func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error { // Run the game thread. wg.Go(func() error { defer cancel() + + var err error + u.mainThread.Call(func() { + if err1 := u.initOnMainThread(options); err1 != nil { + err = err1 + } + }) + if err != nil { + return err + } + return u.loopGame() })