Skip to content

Commit

Permalink
Fixed crash due to a null FrozenGame object pointer.
Browse files Browse the repository at this point in the history
  • Loading branch information
forteri76 committed May 19, 2014
1 parent 6b57c1f commit efc60e5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.jfedor.frozenbubble"
android:versionCode="30"
android:versionName="2.6">
android:versionCode="31"
android:versionName="2.7">

<supports-screens
android:smallScreens="true"
Expand Down
44 changes: 31 additions & 13 deletions src/org/jfedor/frozenbubble/GameView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1007,9 +1007,9 @@ public void cleanUp() {
* the pointers to null to facilitate garbage collection. So I did
* and the crashes went away.
*/
mImagesReady = false;
mFrozenGame1 = null;
mFrozenGame2 = null;
mImagesReady = false;

boolean imagesScaled = (mBackgroundOrig == mBackground.bmp);
mBackgroundOrig.recycle();
Expand Down Expand Up @@ -1200,7 +1200,7 @@ public void cleanUp() {

private void doDraw(Canvas canvas) {
//Log.i("frozen-bubble", "doDraw()");
if (! mImagesReady) {
if (!mImagesReady) {
//Log.i("frozen-bubble", "!mImagesReady, returning");
return;
}
Expand All @@ -1209,9 +1209,13 @@ private void doDraw(Canvas canvas) {
canvas.drawRGB(0, 0, 0);
}
drawBackground(canvas);
mFrozenGame1.paint(canvas, mDisplayScale, mPlayer1DX, mDisplayDY);
if (mFrozenGame1 != null) {
mFrozenGame1.paint(canvas, mDisplayScale, mPlayer1DX, mDisplayDY);
}
if (numPlayers > 1) {
mFrozenGame2.paint(canvas, mDisplayScale, mPlayer2DX, mDisplayDY);
if (mFrozenGame2 != null) {
mFrozenGame2.paint(canvas, mDisplayScale, mPlayer2DX, mDisplayDY);
}
drawWinTotals(canvas);
}
else {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -1835,15 +1838,17 @@ public void newGame() {
}
}

mImagesReady = true;

if (mHighScoreManager != null) {
mHighScoreManager.startLevel(mLevelManager.getLevelIndex());
}
}
}

private void nextLevel() {
mImagesReady = false;
mPlayer1.setGameRef(null);
mFrozenGame1 = null;
mFrozenGame1 = new FrozenGame(mBackground, mBubbles, mBubblesBlind,
mFrozenBubbles, mTargetedBubbles,
mBubbleBlink, mGameWon, mGameLost,
Expand All @@ -1852,6 +1857,7 @@ private void nextLevel() {
mSoundManager, mLevelManager,
mHighScoreManager);
mPlayer1.setGameRef(mFrozenGame1);
mImagesReady = true;
if (mHighScoreManager != null) {
mHighScoreManager.startLevel(mLevelManager.getLevelIndex());
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit efc60e5

Please sign in to comment.