From 0250eb3c4f5cd2b353d7496da37cee620a69f3bf Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 1 Oct 2016 14:16:04 -0700 Subject: [PATCH] Fixed bug 3134 - CalculateXRandRRefreshRate() returns incorrect refresh rate due to floating point truncation. Michael In SDL_x11modes.c the CalculateXRandRRefreshRate() function performs integer math on values that may return fractional results. This causes a value that would be calculated as 59.99972... to be returned as 59. In Linux the xrandr command returns 60Hz for this particular display mode yet SDL returns 59Hz. I suggest this function be updated to correctly round the result of the calculation instead of truncating the result. --- src/video/x11/SDL_x11modes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index e3f8497fc..ba28001f8 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -264,8 +264,8 @@ CheckXRandR(Display * display, int *major, int *minor) static int CalculateXRandRRefreshRate(const XRRModeInfo *info) { - return (info->hTotal - && info->vTotal) ? (info->dotClock / (info->hTotal * info->vTotal)) : 0; + return (info->hTotal && info->vTotal) ? + round(((double)info->dotClock / (double)(info->hTotal * info->vTotal))) : 0; } static SDL_bool