Commit 4c443768 authored by Julian Helfferich's avatar Julian Helfferich

Check for NULL pointers

If the replay file can not be loaded, several pointers are set to NULL.
In this case, several member functions crash if called.

At the moment, these functions are not called since main checks if the
replay file has been loaded successfully. However, if the check is
omitted and the replay file cannot be loaded, the program crashes.

I have added checks for NULL pointers in the member functions of
KBlocksRepWin. Now, the program does not crash even if the check is
omitted.
parent 1b65c40f
......@@ -67,14 +67,18 @@ KBlocksRepWin::~KBlocksRepWin()
void KBlocksRepWin::setGamesPerLine(int count)
{
mpGameScene->setGamesPerLine(count);
if (mpGameScene) {
mpGameScene->setGamesPerLine(count);
}
}
void KBlocksRepWin::setUpdateInterval(int interval)
{
mUpdateInterval = interval;
mUpdateTimer.setInterval(mUpdateInterval);
mpGameScene->setUpdateInterval(interval);
if (mpGameScene) {
mUpdateInterval = interval;
mUpdateTimer.setInterval(mUpdateInterval);
mpGameScene->setUpdateInterval(interval);
}
}
void KBlocksRepWin::setReplayStepLength(int stepLen)
......@@ -99,10 +103,14 @@ bool KBlocksRepWin::replayLoaded()
void KBlocksRepWin::startReplay()
{
mpGameLogic->startGame(mGameCount);
if (mpGameLogic) {
mpGameLogic->startGame(mGameCount);
}
mpGameScene->createGameItemGroups(mGameCount);
mpGameScene->startGame();
if (mpGameScene) {
mpGameScene->createGameItemGroups(mGameCount);
mpGameScene->startGame();
}
mUpdateTimer.start();
}
......@@ -111,10 +119,14 @@ void KBlocksRepWin::stopReplay()
{
mUpdateTimer.stop();
mpGameScene->stopGame();
mpGameScene->deleteGameItemGroups();
if (mpGameScene) {
mpGameScene->stopGame();
mpGameScene->deleteGameItemGroups();
}
mpGameLogic->stopGame();
if (mpGameLogic) {
mpGameLogic->stopGame();
}
}
QString KBlocksRepWin::getTimeString()
......
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