added ignoring remaining level chunks after chunks with wrong size
[rocksndiamonds.git] / src / files.c
index 45f4097f85f734dcb3645116b2bd616285a48726..6839934a166cb2252154a2ad45024865a69e1f86 100644 (file)
@@ -3388,6 +3388,9 @@ static int LoadLevel_GRPX(File *file, int chunk_size, struct LevelInfo *level)
   struct ElementInfo *ei = &element_info[element];
   struct ElementGroupInfo *group = ei->group;
 
+  if (group == NULL)
+    return -1;
+
   xx_ei = *ei;         // copy element data into temporary buffer
   xx_group = *group;   // copy group data into temporary buffer
 
@@ -3588,6 +3591,14 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level,
        int chunk_size_expected =
          (chunk_info[i].loader)(file, chunk_size, level);
 
+       if (chunk_size_expected < 0)
+       {
+         Warn("error reading chunk '%s' in level file '%s'",
+              chunk_name, filename);
+
+         break;
+       }
+
        // the size of some chunks cannot be checked before reading other
        // chunks first (like "HEAD" and "BODY") that contain some header
        // information, so check them here
@@ -3595,6 +3606,8 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level,
        {
          Warn("wrong size (%d) of chunk '%s' in level file '%s'",
               chunk_size, chunk_name, filename);
+
+         break;
        }
       }
     }