From 1b1d02eff1fd0ae24f6314c31411f7080559fa9c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Heli=20Hyv=C3=A4ttinen?= Date: Tue, 14 Jun 2011 05:32:49 +0300 Subject: [PATCH] Fixed crashes when restrating level ...caused by list of moving items not cleared when setting up map, leaving already deleted objects in the list. --- seascene.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/seascene.cpp b/seascene.cpp index c0bda9a..b6ba59b 100644 --- a/seascene.cpp +++ b/seascene.cpp @@ -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++) -- 1.7.9.5