From 3c0b0f4b85c60b69c694ebb140e72395f51a77e4 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 1 Apr 2026 16:42:14 -0700
Subject: [PATCH] Fixed crash if SDL_LoadBMP_RW() fails (thanks @smcv!)
---
src/sdl2_compat.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 9ba967e7..5802a0d4 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -4069,7 +4069,7 @@ SDL_LoadBMP_RW(SDL2_RWops *rwops2, int freesrc)
SDL_RWclose(rwops2);
}
- if (SDL_BITSPERPIXEL(retval->format) < 8) { /* SDL3 can provide BMPs that are < 8bpp. In SDL2, these would get converted to 8bpp. */
+ if (retval && SDL_BITSPERPIXEL(retval->format) < 8) { /* SDL3 can provide BMPs that are < 8bpp. In SDL2, these would get converted to 8bpp. */
SDL_Surface *cvt = SDL3_ConvertSurfaceAndColorspace(retval, SDL_PIXELFORMAT_INDEX8, SDL3_GetSurfacePalette(retval), SDL3_GetSurfaceColorspace(retval), 0);
SDL3_DestroySurface(retval);
retval = cvt; /* if conversion failed, Surface3to2(), below, will notice. */