fixed crash bug caused by accessing invalid (off-playfield) array positions
[rocksndiamonds.git] / src / tools.c
index bf79b048d344368bf064bbc992bf98a18c4cf301..9fe777c90e0f0b180ff7c6ea1936f83176fb11ae 100644 (file)
@@ -1506,7 +1506,9 @@ int getGraphicAnimationFrameXY(int graphic, int lx, int ly)
     return sync_frame % g->anim_frames;
   }
 
-  return getGraphicAnimationFrame(graphic, GfxFrame[lx][ly]);
+  int sync_frame = (IN_LEV_FIELD(lx, ly) ? GfxFrame[lx][ly] : -1);
+
+  return getGraphicAnimationFrame(graphic, sync_frame);
 }
 
 void getGraphicSourceBitmap(int graphic, int tilesize, Bitmap **bitmap)
@@ -1998,6 +2000,9 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element,
 
   if (IN_LEV_FIELD(lx, ly))
   {
+    if (element == EL_EMPTY)
+      element = GfxElementEmpty[lx][ly];
+
     SetRandomAnimationValue(lx, ly);
 
     graphic = el_act_dir2img(element, GfxAction[lx][ly], GfxDir[lx][ly]);
@@ -3957,6 +3962,9 @@ void DrawLevelGraphicAnimationIfNeeded(int x, int y, int graphic)
   if (!IN_LEV_FIELD(x, y) || !IN_SCR_FIELD(sx, sy))
     return;
 
+  if (Tile[x][y] == EL_EMPTY)
+    graphic = el2img(GfxElementEmpty[x][y]);
+
   if (!IS_NEW_FRAME(GfxFrame[x][y], graphic))
     return;
 
@@ -5375,7 +5383,6 @@ unsigned int MoveDoor(unsigned int door_state)
     int num_move_steps = 0;    // number of animation steps for all doors
     int max_move_delay_doors_only = 0; // delay for doors only (no panel)
     int num_move_steps_doors_only = 0; // steps for doors only (no panel)
-    int current_move_delay = 0;
     int start = 0;
     int k;
 
@@ -5635,8 +5642,6 @@ unsigned int MoveDoor(unsigned int door_state)
 
        SkipUntilDelayReached(&door_delay, door_delay_value, &k, last_frame);
 
-       current_move_delay += max_step_delay;
-
        // prevent OS (Windows) from complaining about program not responding
        CheckQuitEvent();
       }
@@ -9951,7 +9956,7 @@ static const unsigned __int64 epoch = ((unsigned __int64) 116444736000000000ULL)
  * Note: this function is not for Win32 high precision timing purpose. See
  * elapsed_time().
  */
-int gettimeofday_windows(struct timeval * tp, struct timezone * tzp)
+static int gettimeofday_windows(struct timeval * tp, struct timezone * tzp)
 {
   FILETIME    file_time;
   SYSTEMTIME  system_time;