mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 18:52:44 +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 (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
chError <-chan error
|
chError <-chan error
|
||||||
running bool
|
running bool
|
||||||
|
mobileMutex sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
func update() error {
|
func update() error {
|
||||||
|
mobileMutex.Lock()
|
||||||
|
defer mobileMutex.Unlock()
|
||||||
|
|
||||||
if chError == nil {
|
if chError == nil {
|
||||||
return errors.New("mobile: chError must not be nil: Start is not called yet?")
|
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) {
|
func start(f func(*ebiten.Image) error, width, height int, scale float64, title string) {
|
||||||
|
mobileMutex.Lock()
|
||||||
|
defer mobileMutex.Unlock()
|
||||||
|
|
||||||
running = true
|
running = true
|
||||||
chError = ebiten.RunWithoutMainLoop(f, width, height, scale, title)
|
chError = ebiten.RunWithoutMainLoop(f, width, height, scale, title)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user