diff --git a/server/main.c b/server/main.c index b1c66bf..24b93c4 100644 --- a/server/main.c +++ b/server/main.c @@ -43,6 +43,7 @@ #include #include #include +#include #include "getopt.h" @@ -814,7 +815,16 @@ do_mainloop(void) last_t = t; #ifndef WIN32 gettimeofday (&t, NULL); - t_diff = ((t.tv_sec - last_t.tv_sec) * 1e6 + (t.tv_usec - last_t.tv_usec)); + t_diff = t.tv_sec - last_t.tv_sec; + if ((t_diff + 1) > (LONG_MAX / 1e6)) { + /* We're going to overflow the calculation - probably been to sleep, fudge the values */ + t_diff = 0; + process_lag = 1; + render_lag = (1e6/RENDER_FREQ); + } else { + t_diff *= 1e6; + t_diff += t.tv_usec - last_t.tv_usec; + } #else QueryPerformanceCounter(&t); /*t_diff.HighPart = t.HighPart - last_t.HighPart;