sdl2-compat: Fix SDL_GetDisplayMode funtions

From cbb3b7ee0cbd5773250327435d29f6a1d408cd06 Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Fri, 3 Feb 2023 14:48:54 +0100
Subject: [PATCH] Fix SDL_GetDisplayMode funtions

---
 src/sdl2_compat.c | 24 ++++++++++++++++--------
 src/sdl3_syms.h   |  4 ++--
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index f392c1d..217ddf3 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -3396,19 +3396,27 @@ SDL_GetDisplayMode(int displayIndex, int modeIndex, SDL2_DisplayMode *mode)
 DECLSPEC int SDLCALL
 SDL_GetCurrentDisplayMode(int displayIndex, SDL2_DisplayMode *mode)
 {
-    SDL_DisplayMode dp;
-    int ret = SDL3_GetCurrentDisplayMode(Display_IndexToID(displayIndex), mode ? &dp : NULL);
-    DisplayMode_3to2(&dp, mode);
-    return ret;
+    SDL_DisplayMode *dp = SDL3_GetCurrentDisplayMode(Display_IndexToID(displayIndex));
+    if (dp == NULL) {
+        return -1;
+    }
+    if (mode) {
+        DisplayMode_3to2(dp, mode);
+    }
+    return 0;
 }
 
 DECLSPEC int SDLCALL
 SDL_GetDesktopDisplayMode(int displayIndex, SDL2_DisplayMode *mode)
 {
-    SDL_DisplayMode dp;
-    int ret = SDL3_GetDesktopDisplayMode(Display_IndexToID(displayIndex), mode ? &dp : NULL);
-    DisplayMode_3to2(&dp, mode);
-    return ret;
+    SDL_DisplayMode *dp = SDL3_GetDesktopDisplayMode(Display_IndexToID(displayIndex));
+    if (dp == NULL) {
+        return -1;
+    }
+    if (mode) {
+        DisplayMode_3to2(dp, mode);
+    }
+    return 0;
 }
 
 DECLSPEC int SDLCALL
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 6a562b1..61b4464 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -482,8 +482,8 @@ SDL3_SYM_PASSTHROUGH(const char*,GetVideoDriver,(int a),(a),return)
 SDL3_SYM_PASSTHROUGH(const char*,GetCurrentVideoDriver,(void),(),return)
 SDL3_SYM(const char*,GetDisplayName,(SDL_DisplayID a),(a),return)
 SDL3_SYM(int,GetDisplayBounds,(SDL_DisplayID a, SDL_Rect *b),(a,b),return)
-SDL3_SYM(int,GetDesktopDisplayMode,(SDL_DisplayID a, SDL_DisplayMode *b),(a,b),return)
-SDL3_SYM(int,GetCurrentDisplayMode,(SDL_DisplayID a, SDL_DisplayMode *b),(a,b),return)
+SDL3_SYM(SDL_DisplayMode*,GetDesktopDisplayMode,(SDL_DisplayID a),(a),return)
+SDL3_SYM(SDL_DisplayMode*,GetCurrentDisplayMode,(SDL_DisplayID a),(a),return)
 SDL3_SYM(int,SetWindowFullscreenMode,(SDL_Window *a, const SDL_DisplayMode *b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(Uint32,GetWindowPixelFormat,(SDL_Window *a),(a),return)
 SDL3_SYM(SDL_Window*,CreateWindow,(const char *a, int b, int c, int d, int e, Uint32 f),(a,b,c,d,e,f),return)