[client] x11: prevent possible calibration underflow

This commit is contained in:
Geoffrey McRae 2021-08-05 07:11:23 +10:00
parent a37b527bbd
commit 0603a55492

View file

@ -1175,9 +1175,19 @@ static bool x11WaitFrame(void)
/* every skip we back off the delay */ /* every skip we back off the delay */
if (deltamsc > 1) if (deltamsc > 1)
{ {
delay -= 100; /* prevent underflow */
calibrate = 1; if (delay - 100 < delay)
deltamsc = 0; {
delay -= 100;
calibrate = 1;
deltamsc = 0;
}
else
{
/* if underflow, we are simply too slow, no delay */
delay = 0;
calibrate = CALIBRATION_COUNT;
}
} }
/* if we have finished, print out the delay */ /* if we have finished, print out the delay */
@ -1191,11 +1201,14 @@ static bool x11WaitFrame(void)
lastmsc = msc; lastmsc = msc;
/* minor adjustments if we are still seeing odd skips */ /* minor adjustments if we are still seeing odd skips */
if (deltamsc > 1) if (deltamsc > 1 && delay - 10 < delay)
delay -= 10; delay -= 10;
struct timespec ts = { .tv_nsec = delay * 1000 }; if (delay)
while(nanosleep(&ts, &ts)) {}; {
struct timespec ts = { .tv_nsec = delay * 1000 };
while(nanosleep(&ts, &ts)) {};
}
/* force rendering until we have finished calibration so we can take into /* force rendering until we have finished calibration so we can take into
* account how long it takes for the scene to render */ * account how long it takes for the scene to render */