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 1be6b546b7
commit d6cf199956
2 changed files with 7 additions and 0 deletions

View File

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

6
run.go
View File

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