internal/ui: refactoring: call initOnMainThread on the main thread explicitly

Closes #3042
This commit is contained in:
Hajime Hoshi 2024-07-15 22:07:04 +09:00
parent d4dc2ef5d7
commit 3d385ef0aa

View File

@ -45,10 +45,6 @@ func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error {
u.context = newContext(game) u.context = newContext(game)
if err := u.initOnMainThread(options); err != nil {
return err
}
ctx, cancel := stdcontext.WithCancel(stdcontext.Background()) ctx, cancel := stdcontext.WithCancel(stdcontext.Background())
defer cancel() defer cancel()
@ -64,6 +60,17 @@ func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error {
// Run the game thread. // Run the game thread.
wg.Go(func() error { wg.Go(func() error {
defer cancel() 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() return u.loopGame()
}) })