close down jni thread before saving game to fix occasional assertion

fail occuring when draw and save were in the jni at the same time.
This commit is contained in:
eehouse 2010-03-21 03:10:00 +00:00
parent 5f6c8fd579
commit 62b586d322

View file

@ -333,12 +333,10 @@ public class BoardActivity extends Activity implements UtilCtxt {
return super.onKeyUp( keyCode, event ); return super.onKeyUp( keyCode, event );
} }
@Override
protected void onDestroy() protected void onDestroy()
{ {
if ( 0 != m_jniGamePtr ) { if ( 0 != m_jniGamePtr ) {
byte[] state = XwJNI.game_saveToStream( m_jniGamePtr, null );
Utils.saveGame( this, state, m_path );
if ( null != m_xport ) { if ( null != m_xport ) {
m_xport.waitToStop(); m_xport.waitToStop();
} }
@ -346,8 +344,13 @@ public class BoardActivity extends Activity implements UtilCtxt {
if ( null != m_jniThread ) { if ( null != m_jniThread ) {
m_jniThread.waitToStop(); m_jniThread.waitToStop();
Utils.logf( "onDestroy(): waitToStop() returned" ); Utils.logf( "onDestroy(): waitToStop() returned" );
} }
// This has to happen after the drawing thread is killed
// to avoid the possibility of reentering the jni world.
byte[] state = XwJNI.game_saveToStream( m_jniGamePtr, null );
Utils.saveGame( this, state, m_path );
XwJNI.game_dispose( m_jniGamePtr ); XwJNI.game_dispose( m_jniGamePtr );
m_jniGamePtr = 0; m_jniGamePtr = 0;
} }