internal/ui: bug fix: crash on Windows

Updates #3042
This commit is contained in:
Hajime Hoshi 2024-07-15 22:44:30 +09:00
parent 3d385ef0aa
commit 38d6328e41

View File

@ -37,12 +37,6 @@ func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error {
u.mainThread = thread.NewOSThread()
graphicscommand.SetOSThreadAsRenderThread()
// Set the running state true after the main thread is set, and before initOnMainThread is called (#2742).
// TODO: As the existence of the main thread is the same as the value of `running`, this is redundant.
// Make `mainThread` atomic and remove `running` if possible.
u.setRunning(true)
defer u.setRunning(false)
u.context = newContext(game)
ctx, cancel := stdcontext.WithCancel(stdcontext.Background())
@ -61,6 +55,12 @@ func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error {
wg.Go(func() error {
defer cancel()
// Set the running state true after the main thread is set, and before initOnMainThread is called (#2742).
// TODO: As the existence of the main thread is the same as the value of `running`, this is redundant.
// Make `mainThread` atomic and remove `running` if possible.
u.setRunning(true)
defer u.setRunning(false)
var err error
u.mainThread.Call(func() {
if err1 := u.initOnMainThread(options); err1 != nil {