From 9c1b760016d0ad55ebe5f39f6e3fc272f39b3b68 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 24 May 2019 02:24:18 +0900 Subject: [PATCH] clock: Bug fix: The timer should continue even when the clock is adjusted If the clock is reversed: * lastSystemTime should be reset with the current time * FPS/TPS calculation state should be reset --- internal/clock/clock.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/clock/clock.go b/internal/clock/clock.go index 4a0367a62..8ec9b8fbf 100644 --- a/internal/clock/clock.go +++ b/internal/clock/clock.go @@ -63,6 +63,7 @@ func calcCountFromTPS(tps int64, now int64) int { diff := now - lastSystemTime if diff < 0 { // It is theoretically possible to change the OS clock, so now can be older than lastSystemTime. + lastSystemTime = now return 0 } @@ -101,6 +102,13 @@ func updateFPSAndTPS(now int64, count int) { } fpsCount++ tpsCount += count + if now < lastUpdated { + // It is theoretically possible to change the OS clock, so now can be older than lastSystemTime. + lastUpdated = now + fpsCount = 0 + tpsCount = 0 + return + } if time.Second > time.Duration(now-lastUpdated) { return }