From 7ad61a97edbc2f0f73488388cb14b2a9e66038e6 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 9 May 2017 14:04:30 -0700 Subject: [PATCH] Fix handling long wait times on POSIX's I_WaitVBL usleep only works for sleeping up to one second. The function is also deprecated and nanosleep should be used instead. --- src/posix/sdl/i_system.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/posix/sdl/i_system.cpp b/src/posix/sdl/i_system.cpp index 753589819b..02dc270e46 100644 --- a/src/posix/sdl/i_system.cpp +++ b/src/posix/sdl/i_system.cpp @@ -113,7 +113,12 @@ void I_WaitVBL (int count) { // I_WaitVBL is never used to actually synchronize to the // vertical blank. Instead, it's used for delay purposes. - usleep (1000000 * count / 70); + struct timespec delay, rem; + delay.tv_sec = count / 70; + /* Avoid overflow. Microsec res should be good enough. */ + delay.tv_nsec = (count%70)*1000000/70 * 1000; + while(nanosleep(&delay, &rem) == -1 && errno == EINTR) + delay = rem; } //