mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
mobile: Bug fix: mutex is necessary for start and update
mobile's Start and Update can be called from different threads. Especially, on Android, this behavior is noted explicitly at https://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer
This commit is contained in:
parent
f1927d8aca
commit
7a00f0f599
@ -18,17 +18,22 @@ package mobile
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||
)
|
||||
|
||||
var (
|
||||
chError <-chan error
|
||||
running bool
|
||||
chError <-chan error
|
||||
running bool
|
||||
mobileMutex sync.Mutex
|
||||
)
|
||||
|
||||
func update() error {
|
||||
mobileMutex.Lock()
|
||||
defer mobileMutex.Unlock()
|
||||
|
||||
if chError == nil {
|
||||
return errors.New("mobile: chError must not be nil: Start is not called yet?")
|
||||
}
|
||||
@ -39,6 +44,9 @@ func update() error {
|
||||
}
|
||||
|
||||
func start(f func(*ebiten.Image) error, width, height int, scale float64, title string) {
|
||||
mobileMutex.Lock()
|
||||
defer mobileMutex.Unlock()
|
||||
|
||||
running = true
|
||||
chError = ebiten.RunWithoutMainLoop(f, width, height, scale, title)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user