From fe31be71eb85608319d39ea3037672a4df31bb20 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Fri, 25 Mar 2016 14:59:43 -0700 Subject: [PATCH] protect against unexpected rollover --- interface/src/Application.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c3e2b8284b..381816e81f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -271,8 +271,10 @@ public: while (!_quit) { QThread::sleep(HEARTBEAT_UPDATE_INTERVAL_SECS); auto now = usecTimestampNow(); - auto lastHeartbeatAge = now - _heartbeat; - auto sinceLastReport = now - _lastReport; + + // in the unlikely event that now is less than _heartbeat, don't rollover and confuse ourselves + auto lastHeartbeatAge = (now > _heartbeat) ? now - _heartbeat : 0; + auto sinceLastReport = (now > _lastReport) ? now - _lastReport : 0; auto elapsedMovingAverage = _movingAverage.getAverage(); if (elapsedMovingAverage > _maxElapsedAverage) {