diff --git a/gameforui.go b/gameforui.go index ae642a4bd..99abfaa20 100644 --- a/gameforui.go +++ b/gameforui.go @@ -16,7 +16,6 @@ package ebiten import ( "fmt" - "sync" "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver" ) @@ -25,16 +24,12 @@ type gameForUI struct { game Game offscreen *Image screen *Image - - m sync.Mutex } -var theGameForUI = &gameForUI{} - -func (c *gameForUI) set(game Game) { - c.m.Lock() - defer c.m.Unlock() - c.game = game +func newGameForUI(game Game) *gameForUI { + return &gameForUI{ + game: game, + } } func (c *gameForUI) Layout(outsideWidth, outsideHeight float64, deviceScaleFactor float64) (int, int) { diff --git a/run.go b/run.go index d2eac1521..7de963b8f 100644 --- a/run.go +++ b/run.go @@ -150,10 +150,10 @@ func RunGame(game Game) error { defer atomic.StoreInt32(&isRunGameEnded_, 1) initializeWindowPositionIfNeeded(WindowSize()) - theGameForUI.set(&imageDumperGame{ + g := newGameForUI(&imageDumperGame{ game: game, }) - if err := ui.Get().Run(theGameForUI); err != nil { + if err := ui.Get().Run(g); err != nil { if err == ui.RegularTermination { return nil } diff --git a/run_mobile.go b/run_mobile.go index 363a4b165..85c797518 100644 --- a/run_mobile.go +++ b/run_mobile.go @@ -27,8 +27,7 @@ import ( // Ebiten users should NOT call RunGameWithoutMainLoop. // Instead, functions in github.com/hajimehoshi/ebiten/v2/mobile package calls this. // -// TODO: Remove this. In order to remove this, the uiContext should be in another package. +// TODO: Remove this. In order to remove this, the gameForUI should be in another package. func RunGameWithoutMainLoop(game Game) { - theGameForUI.set(game) - ui.Get().RunWithoutMainLoop(theGameForUI) + ui.Get().RunWithoutMainLoop(newGameForUI(game)) }