SDL: video: wayland: Support displays with a 0 refresh rate

From 35d045584df29c2399e624d15d7723851b16dc39 Mon Sep 17 00:00:00 2001
From: David Gow <[EMAIL REDACTED]>
Date: Mon, 27 Sep 2021 16:57:09 +0800
Subject: [PATCH] video: wayland: Support displays with a 0 refresh rate

Some wayland compositors report the refresh rate as 0. Since we want to
force a minimum refresh rate of 10 frames worth, we were dividing by the
reported refresh rate, causing a divide-by-zero.

If the refresh rate is 0, instead force a frame every second if no frame
callbacks are received.

This fixes bug #4785
---
 src/video/wayland/SDL_waylandopengles.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/video/wayland/SDL_waylandopengles.c b/src/video/wayland/SDL_waylandopengles.c
index f4beb8b6f4..23429dbbd3 100644
--- a/src/video/wayland/SDL_waylandopengles.c
+++ b/src/video/wayland/SDL_waylandopengles.c
@@ -129,7 +129,9 @@ Wayland_GLES_SwapWindow(_THIS, SDL_Window *window)
     if (swap_interval != 0) {
         struct wl_display *display = ((SDL_VideoData *)_this->driverdata)->display;
         SDL_VideoDisplay *sdldisplay = SDL_GetDisplayForWindow(window);
-        const Uint32 max_wait = SDL_GetTicks() + (10000 / sdldisplay->current_mode.refresh_rate);  /* ~10 frames, so we'll progress even if throttled to zero. */
+        /* ~10 frames (or 1 sec), so we'll progress even if throttled to zero. */
+        const Uint32 max_wait = SDL_GetTicks() + (sdldisplay->current_mode.refresh_rate ?
+                                                  (10000 / sdldisplay->current_mode.refresh_rate) : 1000);
         while (SDL_AtomicGet(&data->swap_interval_ready) == 0) {
             Uint32 now;