From 5450ad34f402c8278b25301e44bb6828aac04f83 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Mon, 10 Mar 2025 21:17:58 +0100 Subject: [PATCH] fixed crash bug caused by freeing custom game tile size graphics twice This crash bug was caused by a bug in managing bitmap pointers for scaled images when using a game tile size smaller than the standard tile size with game graphics already prepared for the smaller size, resulting in freeing the same bitmap pointer twice, causing a crash. (cherry picked from commit b2c29840c1642785ccbb95fdbed36d10c16739a1) --- src/libgame/system.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/libgame/system.c b/src/libgame/system.c index 107de5d5..685a01e2 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -1393,13 +1393,27 @@ static void CreateScaledBitmaps(Bitmap **bitmaps, int zoom_factor, bitmaps[IMG_BITMAP_2x2] = tmp_bitmap_16; bitmaps[IMG_BITMAP_1x1] = tmp_bitmap_32; - if (width_0 != width_1) + // store the "game" bitmap (with game tile sized graphics), if not already stored + + int tmp_bitmap_0_nr = -1; + + for (i = 0; i < NUM_IMG_BITMAPS; i++) + if (bitmaps[i] == tmp_bitmap_0) + tmp_bitmap_0_nr = i; + + if (tmp_bitmap_0_nr == -1) // game tile size bitmap not stored + { + // store pointer of game tile size bitmap (not used for any other size) bitmaps[IMG_BITMAP_CUSTOM] = tmp_bitmap_0; - if (bitmaps[IMG_BITMAP_CUSTOM]) + // set game bitmap pointer to game tile size bitmap of other size bitmaps[IMG_BITMAP_PTR_GAME] = bitmaps[IMG_BITMAP_CUSTOM]; + } else - bitmaps[IMG_BITMAP_PTR_GAME] = bitmaps[IMG_BITMAP_STANDARD]; + { + // set game bitmap pointer to corresponding sized bitmap + bitmaps[IMG_BITMAP_PTR_GAME] = bitmaps[tmp_bitmap_0_nr]; + } // store the "final" (up-scaled) original bitmap, if not already stored -- 2.34.1