Handle case where we want to open a game that's already open (likely

in the process of being closed.) If we're successful in getting a
JNIThread object that's already initialized, re-use it, closing only
the JNI part (which probably can't be cleanly re-used with a different
Context.) I worry about the case where the thread's event queue isn't
empty, so there's an assert to catch that case.
This commit is contained in:
Eric House 2016-05-17 21:08:03 -07:00
parent 79efbd2076
commit 80ebcff4c9
2 changed files with 24 additions and 14 deletions

View file

@ -1967,7 +1967,13 @@ public class GamesListDelegate extends ListDelegateBase
private void startFirstHasDict( long rowid ) private void startFirstHasDict( long rowid )
{ {
if ( -1 != rowid && DBUtils.haveGame( m_activity, rowid ) ) { if ( -1 != rowid && DBUtils.haveGame( m_activity, rowid ) ) {
if ( GameUtils.gameDictsHere( m_activity, rowid ) ) { boolean haveDict;
try {
haveDict = GameUtils.gameDictsHere( m_activity, rowid );
} catch ( GameLock.GameLockedException gle ) {
haveDict = true;
}
if ( haveDict ) {
launchGame( rowid ); launchGame( rowid );
} }
} }
@ -2321,18 +2327,12 @@ public class GamesListDelegate extends ListDelegateBase
private void tryStartsFromIntent( Intent intent ) private void tryStartsFromIntent( Intent intent )
{ {
try {
startFirstHasDict( intent ); startFirstHasDict( intent );
startNewNetGame( intent ); startNewNetGame( intent );
startHasGameID( intent ); startHasGameID( intent );
startRematch( intent ); startRematch( intent );
tryAlert( intent ); tryAlert( intent );
tryNFCIntent( intent ); tryNFCIntent( intent );
} catch ( GameLock.GameLockedException gle ) {
DbgUtils.loge( gle );
showToast( "Finishing; game already open" ); // FIX ME!!!
finish();
}
} }
private void doOpenGame( Object[] params ) private void doOpenGame( Object[] params )

View file

@ -195,8 +195,18 @@ public class JNIThread extends Thread {
m_context = context; m_context = context;
m_drawer = drawer; m_drawer = drawer;
m_handler = handler; m_handler = handler;
m_jniGamePtr = XwJNI.initJNI( m_rowid );
if ( null == m_lock ) {
m_lock = new GameLock( m_rowid, true ).lock(); m_lock = new GameLock( m_rowid, true ).lock();
} else {
m_jniGamePtr.release(); // let the old game copy go
}
// If this isn't true then the queue has to be allowed to empty,
// working on the old game state, before we can re-use any of this.
Assert.assertTrue( 0 == m_queue.size() );
m_jniGamePtr = XwJNI.initJNI( m_rowid );
String[] dictNames = GameUtils.dictNames( context, m_lock ); String[] dictNames = GameUtils.dictNames( context, m_lock );
DictUtils.DictPairs pairs = DictUtils.openDicts( context, dictNames ); DictUtils.DictPairs pairs = DictUtils.openDicts( context, dictNames );