Skip to content

Commit 9a8de34

Browse files
committed
add lower bound to idealSleepTime
1 parent 0973dd6 commit 9a8de34

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/webots/engine/WbSimulationWorld.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ void WbSimulationWorld::step() {
191191
// How long should we have slept to be in real-time?
192192
double idealSleepTime = timeStep - (elapsed - mSleepRealTime);
193193
// Limit to timeStep to avoid weird behavior on large pauses (e.g., on startup)
194-
if (idealSleepTime > timeStep)
195-
idealSleepTime = timeStep;
194+
// We also can't wait less than 0 ms.
195+
idealSleepTime = qBound(0.0, idealSleepTime, timeStep);
196196
// computing the mean of an history of several time values
197197
// improves significantly the stability of the algorithm.
198198
// Moreover it improves the stability of simulations where
@@ -205,8 +205,6 @@ void WbSimulationWorld::step() {
205205
mean += v;
206206
mean /= mIdealSleepTimeHistory.size();
207207
mSleepRealTime = mean;
208-
if (mSleepRealTime < 0.0)
209-
mSleepRealTime = 0.0;
210208

211209
mTimer->start(mSleepRealTime);
212210
}

0 commit comments

Comments
 (0)