SDL: Fixed crash if SDL_GetDisplays() is called before video is initialized

From c3d3c2c672cbba2dad2363afe1ccc7c528910ad8 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 29 Mar 2023 14:44:03 -0700
Subject: [PATCH] Fixed crash if SDL_GetDisplays() is called before video is
 initialized

---
 src/video/SDL_video.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 2ead29e6d047..def279a533fe 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -744,6 +744,13 @@ SDL_DisplayID *SDL_GetDisplays(int *count)
     int i;
     SDL_DisplayID *displays;
 
+    if (!_this) {
+        if (count) {
+            *count = 0;
+        }
+        return SDL_UninitializedVideo();
+    }
+
     displays = (SDL_DisplayID *)SDL_malloc((_this->num_displays + 1) * sizeof(*displays));
     if (displays) {
         if (count) {
@@ -794,8 +801,7 @@ int SDL_GetDisplayIndex(SDL_DisplayID displayID)
     int display_index;
 
     if (!_this) {
-        SDL_UninitializedVideo();
-        return -1;
+        return SDL_UninitializedVideo();
     }
 
     for (display_index = 0; display_index < _this->num_displays; ++display_index) {