SDL: Fixed crash if the X11 display doesn't have a resource manager property

From 85f33fe86698ca154ef3cecaaecfd8128a97121a Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 27 May 2023 20:42:07 -0700
Subject: [PATCH] Fixed crash if the X11 display doesn't have a resource
 manager property

---
 src/video/x11/SDL_x11modes.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c
index 59920974d283..fea113963e62 100644
--- a/src/video/x11/SDL_x11modes.c
+++ b/src/video/x11/SDL_x11modes.c
@@ -190,7 +190,7 @@ static float GetGlobalContentScale(SDL_VideoDevice *_this)
         {
             SDL_VideoData *data = _this->driverdata;
             Display *display = data->display;
-            char * resource_manager;
+            char *resource_manager;
             XrmDatabase db;
             XrmValue value;
             char *type;
@@ -198,16 +198,18 @@ static float GetGlobalContentScale(SDL_VideoDevice *_this)
             X11_XrmInitialize();
 
             resource_manager = X11_XResourceManagerString(display);
-            db = X11_XrmGetStringDatabase(resource_manager);
-
-            // Get the value of Xft.dpi from the Database
-            if (X11_XrmGetResource(db, "Xft.dpi", "String", &type, &value)) {
-                if (value.addr && type && SDL_strcmp(type, "String") == 0) {
-                    int dpi = SDL_atoi(value.addr);
-                    scale_factor  = dpi / 96.0;
+            if (resource_manager) {
+                db = X11_XrmGetStringDatabase(resource_manager);
+
+                // Get the value of Xft.dpi from the Database
+                if (X11_XrmGetResource(db, "Xft.dpi", "String", &type, &value)) {
+                    if (value.addr && type && SDL_strcmp(type, "String") == 0) {
+                        int dpi = SDL_atoi(value.addr);
+                        scale_factor  = dpi / 96.0;
+                    }
                 }
+                X11_XrmDestroyDatabase(db);
             }
-            X11_XrmDestroyDatabase(db);
         }
 
         /* If that failed, try the GDK_SCALE envvar... */