From 2d27c0a7640c1ce8e96538f1425ef86a5c44b6c6 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Mon, 2 May 2022 21:40:39 +0200 Subject: [PATCH] add assertions to avoid crash with wrongly indexed graphics --- src/stratagus/player.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/stratagus/player.cpp b/src/stratagus/player.cpp index 59668dca5..86be75d57 100644 --- a/src/stratagus/player.cpp +++ b/src/stratagus/player.cpp @@ -1287,6 +1287,8 @@ void GraphicPlayerPixels(int colorIndex, const CGraphic &sprite) Assert(SDL_MUSTLOCK(sprite.Surface) == 0); std::vector sdlColors = std::vector(PlayerColorsRGB[colorIndex].begin(), PlayerColorsRGB[colorIndex].end()); + Assert(sprite.Surface->format->palette); + Assert(sprite.Surface->format->palette->ncolors > PlayerColorIndexStart + PlayerColorIndexCount); SDL_SetPaletteColors(sprite.Surface->format->palette, &sdlColors[0], PlayerColorIndexStart, PlayerColorIndexCount); if (sprite.SurfaceFlip) { SDL_SetPaletteColors(sprite.SurfaceFlip->format->palette, &sdlColors[0], PlayerColorIndexStart, PlayerColorIndexCount);