Commit a9a830df authored by Julian Helfferich's avatar Julian Helfferich 💬
Browse files

Replacing freeze cells for testing should only replace one cell at a time

Replacing all cells might trigger a crash in the destructor as
KBlocksItemGroup deletes every item separately.
parent 3f9d162c
......@@ -103,7 +103,7 @@ void testKBlocksItemGroup::refreshPositionShouldClearCache()
TestingKBlocksItemGroup itemGroup(0, &singleGame, &graphics, &sound);
itemGroup.replacePrepareCell(0, new MockSvgItem());
itemGroup.replaceFreezeCells(new MockSvgItem());
itemGroup.replaceFreezeCell(0, new MockSvgItem());
auto *prepareCellBefore = dynamic_cast<MockSvgItem*>(
itemGroup.getPrepareCell(0)
......@@ -171,7 +171,7 @@ void testKBlocksItemGroup::updateGameShouldRefreshItemsOnGameOver()
TestingKBlocksItemGroup itemGroup(0, pSingleGame.get(), pGraphics.get(), pSound.get() );
MockSvgItem *svgItem = new MockSvgItem();
itemGroup.replaceFreezeCells(svgItem);
itemGroup.replaceFreezeCell(0, svgItem);
itemGroup.callUpdateGame();
......
......@@ -60,17 +60,16 @@ public:
addToGroup(maPrepareCells[cellNum]);
}
void replaceFreezeCells(SvgItemInterface* newItem)
void replaceFreezeCell(int cellNum, SvgItemInterface* newItem)
{
for (int i = 0; i < mMaxFreezeCellNum; i++) {
removeFromGroup(maFreezeCells[i]);
delete maFreezeCells[i];
if (cellNum >= mMaxFreezeCellNum) {
return;
}
removeFromGroup(maFreezeCells[cellNum]);
delete maFreezeCells[cellNum];
for (int i = 0; i < mMaxFreezeCellNum; i++) {
maFreezeCells[i] = newItem;
addToGroup(maFreezeCells[i]);
}
maFreezeCells[cellNum] = newItem;
addToGroup(maFreezeCells[cellNum]);
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment