Test for game type before calling resend_all

I have a case where app crashed on launch due to the assert that resend_all()
wasn't being called on a standalone game. That happened because somehow
the game's android-side db entry showed pending packets to send, though the
game type was correct. Fix is to check for game type also, but also to add
a test so comms won't get invoked with a null ptr on release builds.
This commit is contained in:
Eric House 2020-09-25 20:27:21 -07:00
parent d8d894da46
commit 187323192f
3 changed files with 22 additions and 12 deletions

View file

@ -41,6 +41,7 @@ import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify.InviteMeans;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
import org.eehouse.android.xw4.jni.CurGameInfo;
import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
import org.eehouse.android.xw4.jni.DictInfo;
import org.eehouse.android.xw4.jni.GameSummary;
import org.eehouse.android.xw4.jni.XwJNI;
@ -257,7 +258,7 @@ public class DBUtils {
col = cursor.getColumnIndex( DBHelper.SERVERROLE );
tmp = cursor.getInt( col );
summary.serverRole = CurGameInfo.DeviceRole.values()[tmp];
summary.serverRole = DeviceRole.values()[tmp];
}
cursor.close();
}
@ -761,7 +762,10 @@ public class DBUtils {
{
HashMap<Long, CommsConnTypeSet> result = new HashMap<>();
String[] columns = { ROW_ID, DBHelper.CONTYPE };
String selection = String.format( "%s > 0 AND %s != %d", DBHelper.NPACKETSPENDING,
String selection = String.format( "%s != %d AND %s > 0 AND %s != %d",
DBHelper.SERVERROLE,
DeviceRole.SERVER_STANDALONE.ordinal(),
DBHelper.NPACKETSPENDING,
DBHelper.GROUPID, getArchiveGroup( context ) );
initDB( context );
synchronized( s_dbHelper ) {
@ -1333,11 +1337,11 @@ public class DBUtils {
private boolean m_isSolo;
public NeedsNagInfo( long rowid, long nextNag, long lastMove,
CurGameInfo.DeviceRole role ) {
DeviceRole role ) {
m_rowid = rowid;
m_nextNag = nextNag;
m_lastMoveMillis = 1000 * lastMove;
m_isSolo = CurGameInfo.DeviceRole.SERVER_STANDALONE == role;
m_isSolo = DeviceRole.SERVER_STANDALONE == role;
}
public boolean isSolo() {
@ -1369,8 +1373,8 @@ public class DBUtils {
long rowid = cursor.getLong( rowIndex );
long nextNag = cursor.getLong( nagIndex );
long lastMove = cursor.getLong( lastMoveIndex );
CurGameInfo.DeviceRole role =
CurGameInfo.DeviceRole.values()[cursor.getInt( roleIndex )];
DeviceRole role =
DeviceRole.values()[cursor.getInt( roleIndex )];
result[ii] = new NeedsNagInfo( rowid, nextNag, lastMove, role );
}
}

View file

@ -54,6 +54,7 @@ public class XwJNI {
public synchronized long ptr()
{
Assert.assertTrue( 0 != m_ptrGame );
// Log.d( TAG, "ptr(): m_rowid: %d", m_rowid );
return m_ptrGame;
}

View file

@ -2409,17 +2409,22 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1resendAll
( JNIEnv* env, jclass C, GamePtrType gamePtr, jboolean force, jobject jFilter,
jboolean thenAck )
{
jint result;
jint result = 0;
XWJNI_START();
CommsCtxt* comms = state->game.comms;
XP_ASSERT( !!comms );
CommsConnType filter =
NULL == jFilter ? COMMS_CONN_NONE : jEnumToInt( env, jFilter );
result = comms_resendAll( comms, env, filter, force );
if ( thenAck ) {
if ( !!comms ) {
CommsConnType filter =
NULL == jFilter ? COMMS_CONN_NONE : jEnumToInt( env, jFilter );
result = comms_resendAll( comms, env, filter, force );
if ( thenAck ) {
#ifdef XWFEATURE_COMMSACK
comms_ackAny( comms, env );
comms_ackAny( comms, env );
#endif
}
} else {
/* I've seen this once, but wasn't reproducible */
XP_LOGFF( "ERROR: called with null comms" );
}
XWJNI_END();
return result;