From 55e9a861d0436878b41b263396c2b310e1e40402 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 19 Jan 2019 03:26:32 +0900 Subject: [PATCH] ui: Bug fix: isRunning should never be 'false' even after Run on GopherJS --- internal/web/js.go | 5 +++++ internal/web/notjs.go | 4 ++++ run.go | 6 +++++- 3 files changed, 14 insertions(+), 1 deletion(-) 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