ui: Bug fix: isRunning should never be 'false' even after Run on GopherJS

This commit is contained in:
Hajime Hoshi 2019-01-19 03:26:32 +09:00
parent 58cc5cb105
commit 55e9a861d0
3 changed files with 14 additions and 1 deletions

View File

@ -17,11 +17,16 @@
package web package web
import ( import (
"runtime"
"strings" "strings"
"github.com/gopherjs/gopherwasm/js" "github.com/gopherjs/gopherwasm/js"
) )
func IsGopherJS() bool {
return runtime.GOOS != "js"
}
func IsBrowser() bool { func IsBrowser() bool {
return true return true
} }

View File

@ -16,6 +16,10 @@
package web package web
func IsGopherJS() bool {
return false
}
func IsBrowser() bool { func IsBrowser() bool {
return false return false
} }

4
run.go
View File

@ -20,6 +20,7 @@ import (
"github.com/hajimehoshi/ebiten/internal/clock" "github.com/hajimehoshi/ebiten/internal/clock"
"github.com/hajimehoshi/ebiten/internal/ui" "github.com/hajimehoshi/ebiten/internal/ui"
"github.com/hajimehoshi/ebiten/internal/web"
) )
var _ = __EBITEN_REQUIRES_GO_VERSION_1_11_OR_LATER__ 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 { func run(width, height int, scale float64, title string, g *graphicsContext, mainloop bool) error {
atomic.StoreInt32(&isRunning, 1) atomic.StoreInt32(&isRunning, 1)
// On GopherJS, run returns immediately.
if !web.IsGopherJS() {
defer atomic.StoreInt32(&isRunning, 0) defer atomic.StoreInt32(&isRunning, 0)
}
if err := ui.Run(width, height, scale, title, g, mainloop); err != nil { if err := ui.Run(width, height, scale, title, g, mainloop); err != nil {
if err == ui.RegularTermination { if err == ui.RegularTermination {
return nil return nil