SDL_image: stb_image: disable thread-locals again and make it use IMG_SetError

From 369baefb9a90c3191207bd4f788fb0ae363a88b6 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sat, 28 May 2022 21:50:02 +0300
Subject: [PATCH] stb_image: disable thread-locals again and make it use
 IMG_SetError

thread-local stuff in stb_image is just errors, and a flipping feature
that never gets used..
---
 IMG_stb.c   |  3 ++-
 stb_image.h | 12 +++++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/IMG_stb.c b/IMG_stb.c
index c166ed8..dc6247f 100644
--- a/IMG_stb.c
+++ b/IMG_stb.c
@@ -44,6 +44,8 @@
 #define ldexp SDL_scalbn
 
 #define STB_IMAGE_STATIC
+#define STBI_NO_THREAD_LOCALS
+#define STBI_FAILURE_USERMSG
 #define STBI_NO_STDIO
 #define STBI_ONLY_PNG
 #define STBI_ONLY_JPEG
@@ -109,7 +111,6 @@ SDL_Surface *IMG_LoadSTB_RW(SDL_RWops *src)
     );
     if ( !pixels ) {
         SDL_RWseek(src, start, RW_SEEK_SET);
-        IMG_SetError("%s", stbi_failure_reason());
         return NULL;
     }
 
diff --git a/stb_image.h b/stb_image.h
index 8422a97..89cfa7e 100644
--- a/stb_image.h
+++ b/stb_image.h
@@ -485,9 +485,11 @@ STBIDEF int      stbi_is_hdr_from_file(FILE *f);
 #endif // STBI_NO_STDIO
 
 
+#if 0 /* SDL_image change */
 // get a VERY brief reason for failure
 // on most compilers (and ALL modern mainstream compilers) this is threadsafe
 STBIDEF const char *stbi_failure_reason  (void);
+#endif /**/
 
 // free the loaded image -- this is just free()
 STBIDEF void     stbi_image_free      (void *retval_from_stbi_load);
@@ -992,6 +994,14 @@ static int      stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp);
 static int      stbi__pnm_is16(stbi__context *s);
 #endif
 
+#ifndef STBI_NO_FAILURE_STRINGS
+#if 1 /* SDL_image change: */
+static int stbi__err(const char *str)
+{
+   IMG_SetError("%s", str);
+   return 0;
+}
+#else /* SDL_image change. */
 static
 #ifdef STBI_THREAD_LOCAL
 STBI_THREAD_LOCAL
@@ -1003,12 +1013,12 @@ STBIDEF const char *stbi_failure_reason(void)
    return stbi__g_failure_reason;
 }
 
-#ifndef STBI_NO_FAILURE_STRINGS
 static int stbi__err(const char *str)
 {
    stbi__g_failure_reason = str;
    return 0;
 }
+#endif /**/
 #endif
 
 static void *stbi__malloc(size_t size)