Fixed crash blitting to an 8-bit surface with no palette

This commit is contained in:
Sam Lantinga
2025-11-10 13:03:00 -08:00
parent 6389f4db4c
commit ff890d1733

View File

@@ -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 SDL_LookupRGBAColor(SDL_HashTable *palette_map, Uint32 pixelvalue, const SDL_Palette *pal)
{ {
Uint8 color_index = 0; Uint8 color_index = 0;
const void *value; if (pal) {
if (SDL_FindInHashTable(palette_map, (const void *)(uintptr_t)pixelvalue, &value)) { const void *value;
color_index = (Uint8)(uintptr_t)value; if (SDL_FindInHashTable(palette_map, (const void *)(uintptr_t)pixelvalue, &value)) {
} else { color_index = (Uint8)(uintptr_t)value;
Uint8 r = (Uint8)((pixelvalue >> 24) & 0xFF); } else {
Uint8 g = (Uint8)((pixelvalue >> 16) & 0xFF); Uint8 r = (Uint8)((pixelvalue >> 24) & 0xFF);
Uint8 b = (Uint8)((pixelvalue >> 8) & 0xFF); Uint8 g = (Uint8)((pixelvalue >> 16) & 0xFF);
Uint8 a = (Uint8)((pixelvalue >> 0) & 0xFF); Uint8 b = (Uint8)((pixelvalue >> 8) & 0xFF);
color_index = SDL_FindColor(pal, r, g, b, a); Uint8 a = (Uint8)((pixelvalue >> 0) & 0xFF);
SDL_InsertIntoHashTable(palette_map, (const void *)(uintptr_t)pixelvalue, (const void *)(uintptr_t)color_index, true); 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; return color_index;
} }