diff --git a/internal/web/js.go b/internal/web/js.go index ee33d14cf..b2ad3f2db 100644 --- a/internal/web/js.go +++ b/internal/web/js.go @@ -17,11 +17,16 @@ package web import ( + "runtime" "strings" "github.com/gopherjs/gopherwasm/js" ) +func IsGopherJS() bool { + return runtime.GOOS != "js" +} + func IsBrowser() bool { return true } diff --git a/internal/web/notjs.go b/internal/web/notjs.go index 65fd6cd89..5e677d863 100644 --- a/internal/web/notjs.go +++ b/internal/web/notjs.go @@ -16,6 +16,10 @@ package web +func IsGopherJS() bool { + return false +} + func IsBrowser() bool { return false } diff --git a/run.go b/run.go index 3663a3142..617ab9feb 100644 --- a/run.go +++ b/run.go @@ -20,6 +20,7 @@ import ( "github.com/hajimehoshi/ebiten/internal/clock" "github.com/hajimehoshi/ebiten/internal/ui" + "github.com/hajimehoshi/ebiten/internal/web" ) var _ = __EBITEN_REQUIRES_GO_VERSION_1_11_OR_LATER__ @@ -91,7 +92,10 @@ var theGraphicsContext atomic.Value func run(width, height int, scale float64, title string, g *graphicsContext, mainloop bool) error { atomic.StoreInt32(&isRunning, 1) - defer atomic.StoreInt32(&isRunning, 0) + // On GopherJS, run returns immediately. + if !web.IsGopherJS() { + defer atomic.StoreInt32(&isRunning, 0) + } if err := ui.Run(width, height, scale, title, g, mainloop); err != nil { if err == ui.RegularTermination { return nil