diff --git a/inputfield.go b/inputfield.go index bf54254..261c736 100644 --- a/inputfield.go +++ b/inputfield.go @@ -1,6 +1,8 @@ package messeji import ( + "sync" + "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/inpututil" "golang.org/x/image/font" @@ -24,6 +26,8 @@ type InputField struct { // readBuffer is where incoming runes are stored before being added to the input buffer. readBuffer []rune + + sync.Mutex } // NewInputField returns a new InputField. See type documentation for more info. @@ -68,13 +72,13 @@ func (f *InputField) SetSelectedFunc(selectedFunc func() (accept bool)) { // Game.Update is called. func (f *InputField) Update() error { f.Lock() + defer f.Unlock() if !f.visible || rectIsZero(f.r) { return nil } if !f.handleKeyboard { - f.Unlock() return f.TextField.Update() } @@ -123,6 +127,5 @@ func (f *InputField) Update() error { f.bufferModified() } - f.Unlock() return f.TextField.Update() }