From 5d4fd0e58b0bede9cefa29b7c0c60fd564edeb17 Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 23 Oct 2020 16:37:28 -0700 Subject: [PATCH] don't dispose gi before game gathering players was failing because disposed gi was pointing at garbage. I'm lucky it didn't segfault. --- .../main/java/org/eehouse/android/xw4/MQTTUtils.java | 1 + .../src/main/java/org/eehouse/android/xw4/Utils.java | 10 ++++++++++ xwords4/android/jni/xwjni.c | 9 ++++----- xwords4/common/board.c | 2 +- xwords4/common/comms.c | 9 +++++---- xwords4/common/knownplyr.c | 1 - xwords4/common/scorebdp.c | 2 +- 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java index 46aed7519..428d723a0 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MQTTUtils.java @@ -316,6 +316,7 @@ public class MQTTUtils extends Thread implements IMqttActionListener, MqttCallba params.put( "myNow", now ); params.put( "loc", LocUtils.getCurLocale( mContext ) ); params.put( "tmpKey", getTmpKey(mContext) ); + params.put( "frstV", Utils.getFirstVersion( mContext ) ); String fcmid = FBMService.getFCMDevID( mContext ); if ( null != fcmid ) { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java index 5f80e83c0..96e009db4 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java @@ -799,6 +799,16 @@ public class Utils { } } + static int getFirstVersion( Context context ) + { + SharedPreferences prefs = + context.getSharedPreferences( HIDDEN_PREFS, + Context.MODE_PRIVATE ); + int firstVersion = prefs.getInt( FIRST_VERSION_KEY, Integer.MAX_VALUE ); + Assert.assertTrueNR( firstVersion < Integer.MAX_VALUE ); + return firstVersion; + } + private static void setFirstBootStatics( Context context ) { if ( null == s_isFirstBootThisVersion ) { diff --git a/xwords4/android/jni/xwjni.c b/xwords4/android/jni/xwjni.c index f21568f5e..446c34178 100644 --- a/xwords4/android/jni/xwjni.c +++ b/xwords4/android/jni/xwjni.c @@ -882,8 +882,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_gi_1from_1stream XWStreamCtxt* stream = streamFromJStream( MPPARM(mpool) env, globalState->vtMgr, jstream ); - CurGameInfo gi; - XP_MEMSET( &gi, 0, sizeof(gi) ); + CurGameInfo gi = {0}; + // XP_MEMSET( &gi, 0, sizeof(gi) ); if ( game_makeFromStream( MPPARM(mpool) env, stream, NULL, &gi, NULL, NULL, NULL, NULL, NULL, NULL ) ) { setJGI( env, jgi, &gi ); @@ -910,7 +910,6 @@ Java_org_eehouse_android_xw4_jni_XwJNI_nli_1to_1stream jbyteArray result; NetLaunchInfo nli = {0}; loadNLI( env, &nli, jnli ); - /* CurGameInfo* gi = makeGI( MPPARM(mpool) env, jgi ); */ XWStreamCtxt* stream = mem_stream_make( MPPARM(mpool) globalState->vtMgr, NULL, 0, NULL ); @@ -1412,9 +1411,9 @@ JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_game_1dispose #endif AndGameGlobals* globals = &state->globals; - destroyGI( MPPARM(mpool) &globals->gi ); - game_dispose( &state->game, env ); + /* Must happen after game_dispose, which uses it */ + destroyGI( MPPARM(mpool) &globals->gi ); destroyDraw( &globals->dctx, env ); destroyXportProcs( &globals->xportProcs, env ); diff --git a/xwords4/common/board.c b/xwords4/common/board.c index 877f6c45a..7375bbcd9 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -879,7 +879,7 @@ board_canHint( const BoardCtxt* board ) && 0 < model_getNumTilesTotal( board->model, board->selPlayer ) && ! board->pti[board->selPlayer].tradeInProgress; if ( canHint ) { - LocalPlayer* lp = &board->gi->players[board->selPlayer]; + const LocalPlayer* lp = &board->gi->players[board->selPlayer]; canHint = lp->isLocal && !LP_IS_ROBOT(lp); } return canHint; diff --git a/xwords4/common/comms.c b/xwords4/common/comms.c index d28a39464..206c6834a 100644 --- a/xwords4/common/comms.c +++ b/xwords4/common/comms.c @@ -1650,7 +1650,7 @@ resendImpl( CommsCtxt* comms, XWEnv xwe, CommsConnType filter, XP_Bool force, XP_U32 now = dutil_getCurSeconds( comms->dutil, xwe ); if ( !force && (now < comms->nextResend) ) { - XP_LOGF( "%s: aborting: %d seconds left in backoff", __func__, + XP_LOGFF( "aborting: %d seconds left in backoff", comms->nextResend - now ); success = XP_FALSE; @@ -1868,7 +1868,7 @@ relayPreProcess( CommsCtxt* comms, XWEnv xwe, XWStreamCtxt* stream, XWHostID* se /* nothing for us to do here if not using relay */ XWRELAY_Cmd cmd = stream_getU8( stream ); - XP_LOGF( "%s(%s)", __func__, relayCmdToStr( cmd ) ); + XP_LOGFF( "(%s)", relayCmdToStr( cmd ) ); switch( cmd ) { case XWRELAY_CONNECT_RESP: @@ -2017,7 +2017,7 @@ relayPreProcess( CommsCtxt* comms, XWEnv xwe, XWStreamCtxt* stream, XWHostID* se XP_LOGF( "%s: dropping relay msg with cmd %d", __func__, (XP_U16)cmd ); } - LOG_RETURNF( "%s", boolToStr(consumed) ); + LOG_RETURNF( "consumed=%s", boolToStr(consumed) ); return consumed; } /* relayPreProcess */ #endif @@ -2065,7 +2065,7 @@ preProcess( CommsCtxt* comms, XWEnv xwe, const CommsAddrRec* useAddr, /* There should be exactly one type associated with an incoming message */ CommsConnType typ = addr_getType( useAddr ); - XP_LOGF( "%s(typ=%s)", __func__, ConnType2Str(typ) ); + XP_LOGFF( "(typ=%s)", ConnType2Str(typ) ); switch ( typ ) { #ifdef XWFEATURE_RELAY @@ -2611,6 +2611,7 @@ comms_gatherPlayers( CommsCtxt* comms, XWEnv xwe, XP_U32 created ) comms_getAddrs( comms, NULL, addrs, &nRecs ); const CurGameInfo* gi = comms->util->gameInfo; + XP_ASSERT( 0 < gi->nPlayers ); if ( kplr_addAddrs( comms->dutil, xwe, gi, addrs, nRecs, created ) ) { if ( 1 ) { XP_LOGFF( "not setting flag :-)" ); diff --git a/xwords4/common/knownplyr.c b/xwords4/common/knownplyr.c index e299428e5..75a1afad6 100644 --- a/xwords4/common/knownplyr.c +++ b/xwords4/common/knownplyr.c @@ -117,7 +117,6 @@ static const XP_UCHAR* figureNameFor( XP_U16 posn, const CurGameInfo* gi ) { const XP_UCHAR* result = NULL; - // int nthRemote = 0; for ( int ii = 0, nthRemote = 0; NULL == result && ii < gi->nPlayers; ++ii ) { diff --git a/xwords4/common/scorebdp.c b/xwords4/common/scorebdp.c index b3ca7284e..7c8c487a8 100644 --- a/xwords4/common/scorebdp.c +++ b/xwords4/common/scorebdp.c @@ -247,7 +247,7 @@ drawScoreBoard( BoardCtxt* board, XWEnv xwe ) totalDim = 0; XP_U16 missingPlayers = server_getMissingPlayers( board->server ); for ( dp = datum, ii = 0; ii < nPlayers; ++ii, ++dp ) { - LocalPlayer* lp = &board->gi->players[ii]; + const LocalPlayer* lp = &board->gi->players[ii]; XP_Bool isMissing = 0 != ((1 << ii) & missingPlayers); /* This is a hack! */