[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

@ -1174,11 +1174,21 @@ static bool x11WaitFrame(void)
{ {
/* every skip we back off the delay */ /* every skip we back off the delay */
if (deltamsc > 1) if (deltamsc > 1)
{
/* prevent underflow */
if (delay - 100 < delay)
{ {
delay -= 100; delay -= 100;
calibrate = 1; calibrate = 1;
deltamsc = 0; 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 */
if (++calibrate == CALIBRATION_COUNT) if (++calibrate == CALIBRATION_COUNT)
@ -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;
if (delay)
{
struct timespec ts = { .tv_nsec = delay * 1000 }; struct timespec ts = { .tv_nsec = delay * 1000 };
while(nanosleep(&ts, &ts)) {}; 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 */