diff --git a/internal/uidriver/mobile/ui.go b/internal/uidriver/mobile/ui.go index ea59d25eb..24c8baf27 100644 --- a/internal/uidriver/mobile/ui.go +++ b/internal/uidriver/mobile/ui.go @@ -18,9 +18,7 @@ package mobile import ( "context" - "errors" "image" - "runtime" "sync" "time" @@ -56,21 +54,7 @@ func Get() *UserInterface { return theUI } -func (u *UserInterface) Render(chError <-chan error) error { - runtime.LockOSThread() - defer runtime.UnlockOSThread() - - if chError == nil { - return errors.New("ui: chError must not be nil") - } - // TODO: Check this is called on the rendering thread - - select { - case err := <-chError: - return err - default: - } - +func (u *UserInterface) Render() { renderCh <- struct{}{} ctx, cancel := context.WithCancel(context.Background()) go func() { @@ -78,7 +62,6 @@ func (u *UserInterface) Render(chError <-chan error) error { cancel() }() opengl.Get().DoWork(ctx) - return nil } type UserInterface struct { diff --git a/mobile/impl_mobile.go b/mobile/impl_mobile.go index 3db4de31d..8cfb7cd3c 100644 --- a/mobile/impl_mobile.go +++ b/mobile/impl_mobile.go @@ -18,6 +18,7 @@ package mobile import ( "errors" + "runtime" "github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten/internal/uidriver/mobile" @@ -29,13 +30,24 @@ var ( ) func update() error { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + if chError == nil { return errors.New("mobile: chError must not be nil: Start is not called yet?") } if !running { return errors.New("mobile: start must be called ahead of update") } - return mobile.Get().Render(chError) + + select { + case err := <-chError: + return err + default: + } + + mobile.Get().Render() + return nil } func start(f func(*ebiten.Image) error, width, height int, scale float64, title string) { diff --git a/mobile/mobile.go b/mobile/mobile.go index 854201c69..8d25d9a0c 100644 --- a/mobile/mobile.go +++ b/mobile/mobile.go @@ -63,6 +63,7 @@ func Start(f func(*ebiten.Image) error, width, height int, scale float64, title // // Update returns error when 1) OpenGL error happens, or 2) f in Start returns error samely as ebiten.Run. func Update() error { + // TODO: Is it safe to call Lock before locking the OS thread? mobileMutex.Lock() defer mobileMutex.Unlock()