From d6cf199956090f479f7e153a6d78b954cb6eea58 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 3 Sep 2016 18:04:22 +0900 Subject: [PATCH] ui: Bug fix: ScreenScale should not cause deadlock (#264) --- internal/loop/run.go | 1 + run.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/internal/loop/run.go b/internal/loop/run.go index d5b471ddf..1e5ba5520 100644 --- a/internal/loop/run.go +++ b/internal/loop/run.go @@ -28,6 +28,7 @@ func CurrentFPS() float64 { } func IsRunning() bool { + // TODO: Need lock? if currentRunContext == nil { return false } diff --git a/run.go b/run.go index 994b0cbf5..fe5d3ab25 100644 --- a/run.go +++ b/run.go @@ -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() }