From 6eb045d3a8a9ab48eee7631e5e4122fd7a320371 Mon Sep 17 00:00:00 2001 From: eehouse Date: Sat, 13 Mar 2010 23:11:23 +0000 Subject: [PATCH] don't crash if exiting without having successfully opened a game. --- .../eehouse/android/xw4/BoardActivity.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java index 1b786fae3..58e877ed1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -115,7 +115,7 @@ public class BoardActivity extends Activity implements UtilCtxt { ab.setNegativeButton( R.string.button_no, lstnr ); dialog = ab.create(); - dialog.setOnDismissListener( makeODL() ); + dialog.setOnDismissListener( makeODLforBlocking() ); break; case PICK_TILE_REQUEST_BLK: @@ -130,7 +130,7 @@ public class BoardActivity extends Activity implements UtilCtxt { ab.setItems( m_texts, lstnr ); dialog = ab.create(); - dialog.setOnDismissListener( makeODL() ); + dialog.setOnDismissListener( makeODLforBlocking() ); break; case QUERY_ENDGAME: dialog = new AlertDialog.Builder( this ) @@ -203,7 +203,7 @@ public class BoardActivity extends Activity implements UtilCtxt { Utils.logf( "dict name: " + m_gi.dictName ); byte[] dictBytes = Utils.openDict( this, m_gi.dictName ); if ( null == dictBytes ) { - Utils.logf( "**** unable to open dict; warn user! ****" ); + Assert.fail(); finish(); } else { m_jniGamePtr = XwJNI.initJNI(); @@ -308,17 +308,19 @@ public class BoardActivity extends Activity implements UtilCtxt { protected void onDestroy() { - byte[] state = XwJNI.game_saveToStream( m_jniGamePtr, null ); - Utils.saveGame( this, state, m_path ); + if ( 0 != m_jniGamePtr ) { + byte[] state = XwJNI.game_saveToStream( m_jniGamePtr, null ); + Utils.saveGame( this, state, m_path ); - if ( null != m_xport ) { - m_xport.waitToStop(); - } + if ( null != m_xport ) { + m_xport.waitToStop(); + } - if ( null != m_jniThread ) { - m_jniThread.waitToStop(); - Utils.logf( "onDestroy(): waitToStop() returned" ); + if ( null != m_jniThread ) { + m_jniThread.waitToStop(); + Utils.logf( "onDestroy(): waitToStop() returned" ); + } XwJNI.game_dispose( m_jniGamePtr ); m_jniGamePtr = 0; } @@ -512,7 +514,7 @@ public class BoardActivity extends Activity implements UtilCtxt { } } - private DialogInterface.OnDismissListener makeODL() + private DialogInterface.OnDismissListener makeODLforBlocking() { return new DialogInterface.OnDismissListener() { public void onDismiss( DialogInterface di ) {