SDL_image: Load files from the base path as a fallback

From e1beb74494756fd39fc227ce62ae271661bd5f36 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 5 Jan 2026 11:55:35 -0800
Subject: [PATCH] Load files from the base path as a fallback

Fixes loading files from Apple resources on macOS
---
 examples/showanim.c  |  8 ++++++++
 examples/showimage.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/examples/showanim.c b/examples/showanim.c
index c70b1f30..c17adfdb 100644
--- a/examples/showanim.c
+++ b/examples/showanim.c
@@ -107,6 +107,14 @@ int main(int argc, char *argv[])
 
         /* Open the image file */
         anim = IMG_LoadAnimation(argv[i]);
+        if (!anim) {
+            char *path = NULL;
+            SDL_asprintf(&path, "%s%s", SDL_GetBasePath(), argv[i]);
+            if (path) {
+                anim = IMG_LoadAnimation(path);
+                SDL_free(path);
+            }
+        }
         if (!anim) {
             SDL_Log("Couldn't load %s: %s\n", argv[i], SDL_GetError());
             continue;
diff --git a/examples/showimage.c b/examples/showimage.c
index 31840486..1b34733c 100644
--- a/examples/showimage.c
+++ b/examples/showimage.c
@@ -53,6 +53,14 @@ static void draw_background(SDL_Renderer *renderer, int w, int h)
 static void set_cursor(const char *cursor_file)
 {
     IMG_Animation *anim = IMG_LoadAnimation(cursor_file);
+    if (!anim) {
+        char *path = NULL;
+        SDL_asprintf(&path, "%s%s", SDL_GetBasePath(), cursor_file);
+        if (path) {
+            anim = IMG_LoadAnimation(path);
+            SDL_free(path);
+        }
+    }
     if (anim) {
         SDL_Cursor *cursor = IMG_CreateAnimatedCursor(anim, 0, 0);
         if (cursor) {
@@ -163,6 +171,14 @@ int main(int argc, char *argv[])
             SDL_Surface *surface, *temp;
 
             surface = IMG_Load(argv[i]);
+            if (!surface) {
+                char *path = NULL;
+                SDL_asprintf(&path, "%s%s", SDL_GetBasePath(), argv[i]);
+                if (path) {
+                    surface = IMG_Load(path);
+                    SDL_free(path);
+                }
+            }
             if (!surface) {
                 SDL_Log("Couldn't load %s: %s\n", argv[i], SDL_GetError());
                 continue;
@@ -185,6 +201,14 @@ int main(int argc, char *argv[])
             }
         } else {
             texture = IMG_LoadTexture(renderer, argv[i]);
+            if (!texture) {
+                char *path = NULL;
+                SDL_asprintf(&path, "%s%s", SDL_GetBasePath(), argv[i]);
+                if (path) {
+                    texture = IMG_LoadTexture(renderer, path);
+                    SDL_free(path);
+                }
+            }
             if (!texture) {
                 SDL_Log("Couldn't load %s: %s\n", argv[i], SDL_GetError());
                 continue;
@@ -195,6 +219,14 @@ int main(int argc, char *argv[])
         /* Save the image file, if desired */
         if (saveFile) {
             SDL_Surface *surface = IMG_Load(argv[i]);
+            if (!surface) {
+                char *path = NULL;
+                SDL_asprintf(&path, "%s%s", SDL_GetBasePath(), argv[i]);
+                if (path) {
+                    surface = IMG_Load(path);
+                    SDL_free(path);
+                }
+            }
             if (surface) {
                 if (!IMG_Save(surface, saveFile)) {
                     SDL_Log("Couldn't save %s: %s\n", saveFile, SDL_GetError());