From 96b719162f9c4a13503ce38214c87c7c802994e3 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 20 Feb 2004 21:41:37 +0000 Subject: [PATCH] Fix crashes if the system clock moves backwards. --- stepmania/src/RageTimer.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stepmania/src/RageTimer.cpp b/stepmania/src/RageTimer.cpp index 9960240fa9..5a5921a9c9 100644 --- a/stepmania/src/RageTimer.cpp +++ b/stepmania/src/RageTimer.cpp @@ -29,7 +29,9 @@ void RageTimer::Touch() float RageTimer::Ago() const { const RageTimer Now; - return Now - *this; + + /* If the system clock has moved backwards (for example, ntpd), don't return negative values. */ + return max( 0.0f, Now - *this ); } float RageTimer::GetDeltaTime() @@ -37,7 +39,9 @@ float RageTimer::GetDeltaTime() const RageTimer Now; const float diff = Difference( Now, *this ); *this = Now; - return diff; + + /* If the system clock has moved backwards (for example, ntpd), don't return negative values. */ + return max( 0.0f, diff ); } /* Get a timer representing half of the time ago as this one. This is