ebiten: bug fix: updating the input state must be protected by a mutex

This commit is contained in:
Hajime Hoshi 2023-01-22 01:49:43 +09:00
parent b79f0394cc
commit 40aa35750c
2 changed files with 3 additions and 3 deletions

View File

@ -148,7 +148,7 @@ func (g *gameForUI) Layout(outsideWidth, outsideHeight float64) (float64, float6
}
func (g *gameForUI) UpdateInputState(fn func(*ui.InputState)) {
fn(&theInputState.state)
theInputState.update(fn)
}
func (g *gameForUI) Update() error {

View File

@ -396,10 +396,10 @@ type inputState struct {
m sync.Mutex
}
func (i *inputState) set(inputState ui.InputState) {
func (i *inputState) update(fn func(*ui.InputState)) {
i.m.Lock()
defer i.m.Unlock()
i.state = inputState
fn(&i.state)
}
func (i *inputState) appendInputChars(runes []rune) []rune {