From ff890d1733f8bd01becd4c6c1432667626e56b60 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 10 Nov 2025 13:03:00 -0800
Subject: [PATCH] Fixed crash blitting to an 8-bit surface with no palette
---
src/video/SDL_pixels.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c
index d7596c9e7357e..45b69ceb11963 100644
--- a/src/video/SDL_pixels.c
+++ b/src/video/SDL_pixels.c
@@ -1217,16 +1217,18 @@ static Uint8 SDL_FindColor(const SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Ui
Uint8 SDL_LookupRGBAColor(SDL_HashTable *palette_map, Uint32 pixelvalue, const SDL_Palette *pal)
{
Uint8 color_index = 0;
- const void *value;
- if (SDL_FindInHashTable(palette_map, (const void *)(uintptr_t)pixelvalue, &value)) {
- color_index = (Uint8)(uintptr_t)value;
- } else {
- Uint8 r = (Uint8)((pixelvalue >> 24) & 0xFF);
- Uint8 g = (Uint8)((pixelvalue >> 16) & 0xFF);
- Uint8 b = (Uint8)((pixelvalue >> 8) & 0xFF);
- Uint8 a = (Uint8)((pixelvalue >> 0) & 0xFF);
- color_index = SDL_FindColor(pal, r, g, b, a);
- SDL_InsertIntoHashTable(palette_map, (const void *)(uintptr_t)pixelvalue, (const void *)(uintptr_t)color_index, true);
+ if (pal) {
+ const void *value;
+ if (SDL_FindInHashTable(palette_map, (const void *)(uintptr_t)pixelvalue, &value)) {
+ color_index = (Uint8)(uintptr_t)value;
+ } else {
+ Uint8 r = (Uint8)((pixelvalue >> 24) & 0xFF);
+ Uint8 g = (Uint8)((pixelvalue >> 16) & 0xFF);
+ Uint8 b = (Uint8)((pixelvalue >> 8) & 0xFF);
+ Uint8 a = (Uint8)((pixelvalue >> 0) & 0xFF);
+ color_index = SDL_FindColor(pal, r, g, b, a);
+ SDL_InsertIntoHashTable(palette_map, (const void *)(uintptr_t)pixelvalue, (const void *)(uintptr_t)color_index, true);
+ }
}
return color_index;
}