From efc60e55df9843f1b2609842cdca7a4765e14a44 Mon Sep 17 00:00:00 2001 From: forteri76 Date: Mon, 19 May 2014 15:00:18 +0000 Subject: [PATCH] Fixed crash due to a null FrozenGame object pointer. --- AndroidManifest.xml | 4 +-- src/org/jfedor/frozenbubble/GameView.java | 44 ++++++++++++++++------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 771847e..c184bba 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="31" + android:versionName="2.7"> 1) { - mFrozenGame2.paint(canvas, mDisplayScale, mPlayer2DX, mDisplayDY); + if (mFrozenGame2 != null) { + mFrozenGame2.paint(canvas, mDisplayScale, mPlayer2DX, mDisplayDY); + } drawWinTotals(canvas); } else { @@ -1800,8 +1804,8 @@ public void newGame() { mLevelManager.goToFirstLevel(); } + mImagesReady = false; mPlayer1.setGameRef(null); - mFrozenGame1 = null; mFrozenGame1 = new FrozenGame(mBackground, mBubbles, mBubblesBlind, mFrozenBubbles, mTargetedBubbles, mBubbleBlink, mGameWon, mGameLost, @@ -1816,7 +1820,6 @@ public void newGame() { if (numPlayers > 1) { mPlayer2.setGameRef(null); - mFrozenGame2 = null; mFrozenGame2 = new FrozenGame(mBackground, mBubbles, mBubblesBlind, mFrozenBubbles, mTargetedBubbles, mBubbleBlink, mGameWon, mGameLost, @@ -1835,6 +1838,8 @@ public void newGame() { } } + mImagesReady = true; + if (mHighScoreManager != null) { mHighScoreManager.startLevel(mLevelManager.getLevelIndex()); } @@ -1842,8 +1847,8 @@ public void newGame() { } private void nextLevel() { + mImagesReady = false; mPlayer1.setGameRef(null); - mFrozenGame1 = null; mFrozenGame1 = new FrozenGame(mBackground, mBubbles, mBubblesBlind, mFrozenBubbles, mTargetedBubbles, mBubbleBlink, mGameWon, mGameLost, @@ -1852,6 +1857,7 @@ private void nextLevel() { mSoundManager, mLevelManager, mHighScoreManager); mPlayer1.setGameRef(mFrozenGame1); + mImagesReady = true; if (mHighScoreManager != null) { mHighScoreManager.startLevel(mLevelManager.getLevelIndex()); } @@ -1933,13 +1939,19 @@ private void resizeBitmaps() { public void restoreState(Bundle map) { synchronized(mSurfaceHolder) { setState(stateEnum.PAUSED); - mFrozenGame1.restoreState(map, mImageList); + if (mFrozenGame1 != null) { + mFrozenGame1.restoreState(map, mImageList); + } if (numPlayers > 1) { numPlayer1GamesWon = map.getInt("numPlayer1GamesWon", 0); numPlayer2GamesWon = map.getInt("numPlayer2GamesWon", 0); - mFrozenGame2.restoreState(map, mImageList); + if (mFrozenGame2 != null) { + mFrozenGame2.restoreState(map, mImageList); + } + } + if (mLevelManager != null) { + mLevelManager.restoreState(map); } - mLevelManager.restoreState(map); if (mHighScoreManager != null) { mHighScoreManager.restoreState(map); } @@ -2041,17 +2053,23 @@ else if ((mHighScoreManager != null) && mShowScores) { public Bundle saveState(Bundle map) { synchronized(mSurfaceHolder) { if (map != null) { - mFrozenGame1.saveState(map); + if (mFrozenGame1 != null) { + mFrozenGame1.saveState(map); + } if (numPlayers > 1) { map.putInt("numPlayers", 2); map.putInt("numPlayer1GamesWon", numPlayer1GamesWon); map.putInt("numPlayer2GamesWon", numPlayer2GamesWon); - mFrozenGame2.saveState(map); + if (mFrozenGame2 != null) { + mFrozenGame2.saveState(map); + } } else { map.putInt("numPlayers", 1); } - mLevelManager.saveState(map); + if (mLevelManager != null) { + mLevelManager.saveState(map); + } if (mHighScoreManager != null) { mHighScoreManager.saveState(map); }