fixed crash bug caused by freeing custom game tile size graphics twice
authorHolger Schemel <info@artsoft.org>
Mon, 10 Mar 2025 20:17:58 +0000 (21:17 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 5 Apr 2025 11:34:36 +0000 (13:34 +0200)
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

index 107de5d5170d7a33185a53051edf2654f7a4f82f..685a01e2852bed84bef50a2d8a6aaefc7621e9dc 100644 (file)
@@ -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