add logging toward catching board layout problems; throw exception

when can't unlock game (possible fix to multiple instances of
GamesListActivity stacking up); cleanup of GamesListDelegate tracking
of open games.
This commit is contained in:
Eric House 2016-04-05 08:18:12 -07:00
parent 21ef6d4e13
commit 8cb2cecc18
7 changed files with 56 additions and 35 deletions

View file

@ -666,8 +666,8 @@ public class BoardDelegate extends DelegateBase
m_jniThreadRef.release(); m_jniThreadRef.release();
m_jniThreadRef = null; m_jniThreadRef = null;
// Assert.assertNull( m_jniThreadRef ); // firing // Assert.assertNull( m_jniThreadRef ); // firing
GamesListDelegate.boardDestroyed( m_rowid );
} }
GamesListDelegate.boardDestroyed( m_rowid );
super.onDestroy(); super.onDestroy();
} }
@ -1464,7 +1464,7 @@ public class BoardDelegate extends DelegateBase
finish(); finish();
GameUtils.launchGame( m_activity, m_rowid, m_haveInvited ); GameUtils.launchGame( getDelegator(), m_rowid, m_haveInvited );
} }
private void setGotGameDict( String getDict ) private void setGotGameDict( String getDict )
@ -1474,7 +1474,7 @@ public class BoardDelegate extends DelegateBase
String msg = getString( R.string.reload_new_dict_fmt, getDict ); String msg = getString( R.string.reload_new_dict_fmt, getDict );
showToast( msg ); showToast( msg );
finish(); finish();
GameUtils.launchGame( m_activity, m_rowid, false ); GameUtils.launchGame( getDelegator(), m_rowid, false );
} }
private XwJNI.XP_Key keyCodeToXPKey( int keyCode ) private XwJNI.XP_Key keyCodeToXPKey( int keyCode )

View file

@ -158,6 +158,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
DbgUtils.logf( "onMeasure: discarding m_dims" ); DbgUtils.logf( "onMeasure: discarding m_dims" );
if ( ++m_dimsTossCount < 4 ) { if ( ++m_dimsTossCount < 4 ) {
m_dims = null; m_dims = null;
m_layoutWidth = m_layoutHeight = 0;
} }
} }
} }
@ -202,7 +203,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
ConnStatusHandler.draw( m_context, canvas, getResources(), ConnStatusHandler.draw( m_context, canvas, getResources(),
m_connTypes, m_isSolo ); m_connTypes, m_isSolo );
} else { } else {
DbgUtils.logf( "board not laid out yet" ); DbgUtils.logf( "BoardView.onDraw(): board not laid out yet" );
} }
} }
} }
@ -213,12 +214,15 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
final int height = getHeight(); final int height = getHeight();
boolean layoutDone = width == m_layoutWidth && height == m_layoutHeight; boolean layoutDone = width == m_layoutWidth && height == m_layoutHeight;
if ( layoutDone ) { if ( layoutDone ) {
// nothing to do DbgUtils.logf( "layoutBoardOnce(): layoutDone true" );
} else if ( null == m_gi ) { } else if ( null == m_gi ) {
// nothing to do either // nothing to do either
DbgUtils.logf( "layoutBoardOnce(): no m_gi" );
} else if ( null == m_jniThread ) { } else if ( null == m_jniThread ) {
// nothing to do either // nothing to do either
DbgUtils.logf( "layoutBoardOnce(): no m_jniThread" );
} else if ( null == m_dims ) { } else if ( null == m_dims ) {
DbgUtils.logf( "layoutBoardOnce(): null m_dims" );
// m_canvas = null; // m_canvas = null;
// need to synchronize?? // need to synchronize??
Paint paint = new Paint(); Paint paint = new Paint();
@ -234,6 +238,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
fontWidth, m_defaultFontHt ); fontWidth, m_defaultFontHt );
// We'll be back.... // We'll be back....
} else { } else {
DbgUtils.logf( "layoutBoardOnce(): DOING IT" );
// If board size has changed we need a new bitmap // If board size has changed we need a new bitmap
int bmHeight = 1 + m_dims.height; int bmHeight = 1 + m_dims.height;
int bmWidth = 1 + m_dims.width; int bmWidth = 1 + m_dims.width;

View file

@ -118,11 +118,15 @@ public class DBUtils {
long maxMillis ) long maxMillis )
{ {
GameSummary result = null; GameSummary result = null;
try {
GameLock lock = new GameLock( rowid, false ).lock( maxMillis ); GameLock lock = new GameLock( rowid, false ).lock( maxMillis );
if ( null != lock ) { if ( null != lock ) {
result = getSummary( context, lock ); result = getSummary( context, lock );
lock.unlock(); lock.unlock();
} }
} catch ( GameLock.GameLockedException gle ) {
DbgUtils.loge( gle );
}
return result; return result;
} }

View file

@ -1166,7 +1166,7 @@ public class GameConfigDelegate extends DelegateBase
&& 0 == m_car.ip_relay_invite.length() ) { && 0 == m_car.ip_relay_invite.length() ) {
showOKOnlyDialog( R.string.no_empty_rooms ); showOKOnlyDialog( R.string.no_empty_rooms );
} else { } else {
GameUtils.launchGameAndFinish( m_activity, m_rowid ); GameUtils.launchGameAndFinish( getDelegator(), m_rowid );
} }
} }

View file

@ -29,13 +29,21 @@ import junit.framework.Assert;
// write lock is. Write-locks are exclusive. // write lock is. Write-locks are exclusive.
public class GameLock { public class GameLock {
private static final boolean DEBUG_LOCKS = false; private static final boolean DEBUG_LOCKS = false;
private static final boolean THROW_ON_LOCKED = true;
private static final int SLEEP_TIME = 100; private static final int SLEEP_TIME = 100;
private static final long ASSERT_TIME = 2000; private static final long ASSERT_TIME = 2000;
private static final long THROW_TIME = 750;
private long m_rowid; private long m_rowid;
private boolean m_isForWrite; private boolean m_isForWrite;
private int m_lockCount; private int m_lockCount;
private StackTraceElement[] m_lockTrace; private StackTraceElement[] m_lockTrace;
static {
Assert.assertTrue( THROW_TIME <= ASSERT_TIME );
}
public static class GameLockedException extends RuntimeException {}
private static HashMap<Long, GameLock> private static HashMap<Long, GameLock>
s_locks = new HashMap<Long,GameLock>(); s_locks = new HashMap<Long,GameLock>();
@ -145,6 +153,8 @@ public class GameLock {
if ( 0 < maxMillis && sleptTime >= maxMillis ) { if ( 0 < maxMillis && sleptTime >= maxMillis ) {
break; break;
} else if ( THROW_ON_LOCKED && sleptTime >= THROW_TIME ) {
throw new GameLockedException();
} else if ( sleptTime >= ASSERT_TIME ) { } else if ( sleptTime >= ASSERT_TIME ) {
if ( DEBUG_LOCKS ) { if ( DEBUG_LOCKS ) {
DbgUtils.logf( "lock %H overlocked", this ); DbgUtils.logf( "lock %H overlocked", this );

View file

@ -843,12 +843,13 @@ public class GameUtils {
return bundle; return bundle;
} }
public static void launchGame( Activity activity, long rowid, public static void launchGame( Delegator delegator, long rowid,
boolean invited ) boolean invited )
{ {
Activity activity = delegator.getActivity();
Bundle extras = makeLaunchExtras( rowid, invited ); Bundle extras = makeLaunchExtras( rowid, invited );
if ( activity instanceof FragActivity ) { if ( activity instanceof FragActivity ) {
FragActivity.addFragment( new BoardFrag(), extras ); FragActivity.addFragment( new BoardFrag(), extras, delegator );
} else { } else {
Intent intent = new Intent( activity, BoardActivity.class ); Intent intent = new Intent( activity, BoardActivity.class );
intent.putExtras( extras ); intent.putExtras( extras );
@ -856,15 +857,15 @@ public class GameUtils {
} }
} }
public static void launchGame( Activity activity, long rowid ) public static void launchGame( Delegator delegator, long rowid )
{ {
launchGame( activity, rowid, false ); launchGame( delegator, rowid, false );
} }
public static void launchGameAndFinish( Activity activity, long rowid ) public static void launchGameAndFinish( Delegator delegator, long rowid )
{ {
launchGame( activity, rowid ); launchGame( delegator, rowid );
activity.finish(); delegator.getActivity().finish();
} }
private static class FeedUtilsImpl extends UtilCtxtImpl { private static class FeedUtilsImpl extends UtilCtxtImpl {

View file

@ -580,7 +580,7 @@ public class GamesListDelegate extends ListDelegateBase
private String m_nameField; private String m_nameField;
private NetLaunchInfo m_netLaunchInfo; private NetLaunchInfo m_netLaunchInfo;
private GameNamer m_namer; private GameNamer m_namer;
private Set<Long> m_launchedGames; private Set<Long> m_launchedGames; // prevent problems with double-taps
private boolean m_menuPrepared; private boolean m_menuPrepared;
private boolean m_moveAfterNewGroup; private boolean m_moveAfterNewGroup;
private Set<Long> m_selGames; private Set<Long> m_selGames;
@ -988,8 +988,10 @@ public class GamesListDelegate extends ListDelegateBase
protected void onDestroy() protected void onDestroy()
{ {
DBUtils.clearDBChangeListener( this ); DBUtils.clearDBChangeListener( this );
if ( s_self == this ) {
s_self = null; s_self = null;
} }
}
protected void onSaveInstanceState( Bundle outState ) protected void onSaveInstanceState( Bundle outState )
{ {
@ -1044,16 +1046,7 @@ public class GamesListDelegate extends ListDelegateBase
if ( hasFocus ) { if ( hasFocus ) {
updateField(); updateField();
if ( 0 != m_launchedGames.size() ) { m_launchedGames.clear();
long rowid = m_launchedGames.iterator().next();
m_launchedGames.remove( rowid );
if ( m_adapter.inExpandedGroup( rowid ) ) {
setSelGame( rowid );
} else {
clearSelections();
}
}
} }
} }
@ -1303,7 +1296,7 @@ public class GamesListDelegate extends ListDelegateBase
if ( !cancelled ) { if ( !cancelled ) {
long rowID = data.getLongExtra( GameUtils.INTENT_KEY_ROWID, long rowID = data.getLongExtra( GameUtils.INTENT_KEY_ROWID,
DBUtils.ROWID_NOTFOUND ); DBUtils.ROWID_NOTFOUND );
GameUtils.launchGame( m_activity, rowID ); GameUtils.launchGame( getDelegator(), rowID );
} }
break; break;
} }
@ -2292,7 +2285,7 @@ public class GamesListDelegate extends ListDelegateBase
long[] rowIDs = { rowID }; long[] rowIDs = { rowID };
doConfirmReset( rowIDs ); doConfirmReset( rowIDs );
} else if ( checkWarnNoDict( rowID ) ) { } else if ( checkWarnNoDict( rowID ) ) {
GameUtils.launchGame( m_activity, rowID ); GameUtils.launchGame( getDelegator(), rowID );
} }
} }
return madeGame; return madeGame;
@ -2306,7 +2299,10 @@ public class GamesListDelegate extends ListDelegateBase
// m_delegator.launchGame( rowid, invited ); // m_delegator.launchGame( rowid, invited );
if ( ! m_launchedGames.contains( rowid ) ) { if ( ! m_launchedGames.contains( rowid ) ) {
m_launchedGames.add( rowid ); m_launchedGames.add( rowid );
GameUtils.launchGame( m_activity, rowid, invited ); if ( m_adapter.inExpandedGroup( rowid ) ) {
setSelGame( rowid );
}
GameUtils.launchGame( getDelegator(), rowid, invited );
} }
} }
@ -2342,9 +2338,14 @@ public class GamesListDelegate extends ListDelegateBase
&& summary.roomName.length() == 0 ) { && summary.roomName.length() == 0 ) {
Assert.fail(); Assert.fail();
} else { } else {
try {
if ( checkWarnNoDict( rowid ) ) { if ( checkWarnNoDict( rowid ) ) {
launchGame( rowid ); launchGame( rowid );
} }
} catch ( GameLock.GameLockedException gle ) {
DbgUtils.loge( gle );
finish();
}
} }
} }
@ -2486,7 +2487,7 @@ public class GamesListDelegate extends ListDelegateBase
.CONFIG_GAME, rowID ); .CONFIG_GAME, rowID );
} else { } else {
// launch it // launch it
GameUtils.launchGame( m_activity, rowID ); GameUtils.launchGame( getDelegator(), rowID );
} }
} }
} }