Fixed crashes when restrating level
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 14 Jun 2011 02:32:49 +0000 (05:32 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 14 Jun 2011 02:32:49 +0000 (05:32 +0300)
...caused by list of moving items not cleared when setting up map,
leaving already deleted objects in the list.

seascene.cpp

index c0bda9a..b6ba59b 100644 (file)
@@ -23,6 +23,10 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
 
     clear();
 
+    //empty the list of moving items
+
+    movingItems_.clear();
+
     //empty the list of free slots
     freeTiles_.clear();
 
@@ -49,6 +53,8 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
     {
         QPointF * pPosition = findRandomFreeSlot();
 
+        qDebug() << "Found a place for a rock";
+
         //If there was no room no point to continue
         if (pPosition == NULL)
             break;
@@ -117,6 +123,8 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
 void SeaScene::spreadGhosts(int ghosts)
 {
 
+    qDebug() << "Preparing to spread ghosts";
+
     //the octopuses and the ship may have moved from their original positions,
     //so the list of free slots must be adjusted to exclude their current positions
 
@@ -124,11 +132,17 @@ void SeaScene::spreadGhosts(int ghosts)
 
     foreach (QGraphicsItem* pItem, movingItems_)
     {
-    //TODO
+        if (pItem == NULL)
+        {
+ //           qDebug() << "NULL item in movingItems_";
+            continue;
+        }
+
         //round x and y down to fit the slot size
         int x = pItem->x();
         x = x/40;
         x = x*40;
+
         int y = pItem->y();
         y = y/40;
         y=y*40;
@@ -159,6 +173,7 @@ void SeaScene::spreadGhosts(int ghosts)
 
     }
 
+
     //spread ghosts in random free slots
 
     for (int i=0; i < ghosts; i++)