ui: Bug fix: ScreenScale should not cause deadlock (#264)

This commit is contained in:
Hajime Hoshi 2016-09-03 18:04:22 +09:00
parent 750c2e08df
commit d08beef412
2 changed files with 7 additions and 0 deletions

View File

@ -28,6 +28,7 @@ func CurrentFPS() float64 {
}
func IsRunning() bool {
// TODO: Need lock?
if currentRunContext == nil {
return false
}

6
run.go
View File

@ -15,6 +15,7 @@
package ebiten
import (
"math"
"sync/atomic"
"github.com/hajimehoshi/ebiten/internal/loop"
@ -143,7 +144,12 @@ func SetScreenScale(scale float64) {
// ScreenScale returns the current screen scale.
//
// If Run is not called, this returns NaN.
//
// This function is concurrent-safe.
func ScreenScale() float64 {
if !loop.IsRunning() {
return math.NaN()
}
return ui.ScreenScale()
}