internal/ui: call setRunning(true) at a more appropriate timing

This commit is contained in:
Hajime Hoshi 2024-07-15 22:46:54 +09:00
parent 38d6328e41
commit f9b0451e08
5 changed files with 11 additions and 6 deletions

View File

@ -55,12 +55,6 @@ 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 {
@ -71,6 +65,9 @@ func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error {
return err
}
// setRunning(true) should be called in initOnMainThread for each platform.
defer u.setRunning(false)
return u.loopGame()
})

View File

@ -821,6 +821,8 @@ func (u *UserInterface) createWindow() error {
return err
}
u.window = window
// Set the running state true just a window is set (#2742).
u.setRunning(true)
// The position must be set before the size is set (#1982).
// setWindowSizeInDIP refers the current monitor's device scale.

View File

@ -749,6 +749,8 @@ func (u *UserInterface) shouldFocusFirst(options *RunOptions) bool {
}
func (u *UserInterface) initOnMainThread(options *RunOptions) error {
u.setRunning(true)
if u.shouldFocusFirst(options) {
canvas.Call("focus")
}

View File

@ -73,6 +73,8 @@ func (u *UserInterface) init() error {
}
func (u *UserInterface) initOnMainThread(options *RunOptions) error {
u.setRunning(true)
n := C.ebitengine_Initialize()
g, lib, err := newGraphicsDriver(&graphicsDriverCreatorImpl{
nativeWindow: n,

View File

@ -69,6 +69,8 @@ func (u *UserInterface) init() error {
}
func (u *UserInterface) initOnMainThread(options *RunOptions) error {
u.setRunning(true)
g, lib, err := newGraphicsDriver(&graphicsDriverCreatorImpl{}, options.GraphicsLibrary)
if err != nil {
return err