diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java index 7942f84f5..008b33de5 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -216,15 +216,28 @@ public class GameUtils { public static long dupeGame( Context context, long rowidIn ) { long rowid = DBUtils.ROWID_NOTFOUND; - GameLock lockSrc = new GameLock( rowidIn, false ).lock( 300 ); + GameLock lockSrc = null; + + JNIThread thread = JNIThread.getRetained( rowidIn, false ); + if ( null != thread ) { + lockSrc = thread.getLock(); + } else { + lockSrc = new GameLock( rowidIn, false ).lock( 300 ); + } + if ( null != lockSrc ) { boolean juggle = CommonPrefs.getAutoJuggle( context ); GameLock lockDest = resetGame( context, lockSrc, null, juggle ); rowid = lockDest.getRowid(); lockDest.unlock(); - lockSrc.unlock(); + + if ( null != thread ) { + thread.release(); + } else { + lockSrc.unlock(); + } } else { - DbgUtils.logf( "dupeGame: unable to open rowid %d", rowidIn ); + DbgUtils.logdf( "dupeGame: unable to open rowid %d", rowidIn ); } return rowid; } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java index f12cb2a04..d4bab59ea 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -1246,8 +1246,10 @@ public class GamesListDelegate extends ListDelegateBase case NEW_FROM: long curID = (Long)params[0]; long newid = GameUtils.dupeGame( m_activity, curID ); - m_selGames.add( newid ); - reloadGame( newid ); + if ( DBUtils.ROWID_NOTFOUND != newid ) { + m_selGames.add( newid ); + reloadGame( newid ); + } break; case SET_HIDE_NEWGAME_BUTTONS: @@ -2130,7 +2132,9 @@ public class GamesListDelegate extends ListDelegateBase long newid; if ( null == btAddr && null == phone && null == relayID ) { newid = GameUtils.dupeGame( m_activity, srcRowID ); - DBUtils.setName( m_activity, newid, gameName ); + if ( DBUtils.ROWID_NOTFOUND != newid ) { + DBUtils.setName( m_activity, newid, gameName ); + } } else { long groupID = DBUtils.getGroupForGame( m_activity, srcRowID ); newid = GameUtils.makeNewMultiGame( m_activity, groupID, dict, @@ -2352,7 +2356,9 @@ public class GamesListDelegate extends ListDelegateBase private void launchGame( long rowid, boolean invited ) { - if ( ! m_launchedGames.contains( rowid ) ) { + if ( DBUtils.ROWID_NOTFOUND == rowid ) { + DbgUtils.logdf( "launchGame(): dropping bad rowid" ); + } else if ( ! m_launchedGames.contains( rowid ) ) { m_launchedGames.add( rowid ); if ( m_adapter.inExpandedGroup( rowid ) ) { setSelGame( rowid );