diff --git a/xwords4/android/XWords4/jni/anddict.c b/xwords4/android/XWords4/jni/anddict.c index 4f8500919..0242f9b73 100644 --- a/xwords4/android/XWords4/jni/anddict.c +++ b/xwords4/android/XWords4/jni/anddict.c @@ -422,24 +422,32 @@ and_dictionary_make_empty( MPFORMAL JNIEnv* env, JNIUtilCtxt* jniutil ) } void -makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, PlayerDicts* dicts, +makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, + DictionaryCtxt** dictp, PlayerDicts* dicts, jobjectArray jdicts, jobjectArray jnames, jstring jlang ) { int ii; jsize len = (*env)->GetArrayLength( env, jdicts ); XP_ASSERT( len == (*env)->GetArrayLength( env, jnames ) ); - for ( ii = 0; ii < VSIZE(dicts->dicts); ++ii ) { + for ( ii = 0; ii <= VSIZE(dicts->dicts); ++ii ) { DictionaryCtxt* dict = NULL; if ( ii < len ) { jobject jdict = (*env)->GetObjectArrayElement( env, jdicts, ii ); - jstring jname = (*env)->GetObjectArrayElement( env, jnames, ii ); - dict = makeDict( MPPARM(mpool) env, jniutil, jdict, jname, jlang ); - XP_ASSERT( !!dict ); - (*env)->DeleteLocalRef( env, jdict ); - (*env)->DeleteLocalRef( env, jname ); - } - dicts->dicts[ii] = dict; + if ( NULL != jdict ) { + jstring jname = (*env)->GetObjectArrayElement( env, jnames, ii ); + dict = makeDict( MPPARM(mpool) env, jniutil, jdict, jname, jlang ); + XP_ASSERT( !!dict ); + (*env)->DeleteLocalRef( env, jdict ); + (*env)->DeleteLocalRef( env, jname ); + } + } + if ( 0 == ii ) { + *dictp = dict; + } else { + XP_ASSERT( ii-1 < VSIZE( dicts->dicts ) ); + dicts->dicts[ii-1] = dict; + } } } diff --git a/xwords4/android/XWords4/jni/anddict.h b/xwords4/android/XWords4/jni/anddict.h index 4a0f05f4a..02dc36959 100644 --- a/xwords4/android/XWords4/jni/anddict.h +++ b/xwords4/android/XWords4/jni/anddict.h @@ -32,8 +32,10 @@ dict_splitFaces( DictionaryCtxt* dict, const XP_U8* bytes, DictionaryCtxt* makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, jbyteArray bytes, jstring jname, jstring jlang ); -void makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, PlayerDicts* dicts, - jobjectArray jdicts, jobjectArray jnames, jstring jlang ); +void makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, + DictionaryCtxt** dict, + PlayerDicts* dicts, jobjectArray jdicts, jobjectArray jnames, + jstring jlang ); void destroyDicts( PlayerDicts* dicts ); diff --git a/xwords4/android/XWords4/jni/xwjni.c b/xwords4/android/XWords4/jni/xwjni.c index 649ba2837..1a46e1690 100644 --- a/xwords4/android/XWords4/jni/xwjni.c +++ b/xwords4/android/XWords4/jni/xwjni.c @@ -59,6 +59,9 @@ makeGI( MPFORMAL JNIEnv* env, jobject j_gi ) jenumFieldToInt( env, j_gi, "serverRole", "org/eehouse/android/xw4/jni/CurGameInfo$DeviceRole"); + getString( env, j_gi, "dictName", buf, VSIZE(buf) ); + gi->dictName = copyString( mpool, buf ); + XP_ASSERT( gi->nPlayers <= MAX_NUM_PLAYERS ); jobject jplayers; @@ -106,6 +109,7 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi ) setBool( env, jgi, "hintsNotAllowed", gi->hintsNotAllowed ); setBool( env, jgi, "timerEnabled", gi->timerEnabled ); setBool( env, jgi, "allowPickTiles", gi->allowPickTiles ); + setString( env, jgi, "dictName", gi->dictName ); intToJenumField( env, jgi, gi->phoniesAction, "phoniesAction", "org/eehouse/android/xw4/jni/CurGameInfo$XWPhoniesChoice" ); @@ -394,15 +398,17 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame game_makeNewGame( MPPARM(mpool) &state->game, gi, globals->util, dctx, &cp, globals->xportProcs ); + DictionaryCtxt* dict; PlayerDicts dicts; - makeDicts( MPPARM(mpool) env, globals->jniutil, &dicts, j_dicts, j_names, - j_lang ); + makeDicts( MPPARM(mpool) env, globals->jniutil, &dict, &dicts, j_dicts, + j_names, j_lang ); #ifdef STUBBED_DICT if ( !dict ) { XP_LOGF( "falling back to stubbed dict" ); dict = make_stubbed_dict( MPPARM_NOCOMMA(mpool) ); } #endif + model_setDictionary( state->game.model, dict ); model_setPlayerDicts( state->game.model, &dicts ); XWJNI_END(); } /* makeNewGame */ @@ -440,6 +446,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream jobject jutil, jobject jniu, jobject jdraw, jobject jcp, jobject jprocs ) { jboolean result; + DictionaryCtxt* dict; PlayerDicts dicts; XWJNI_START_GLOBALS(); @@ -447,8 +454,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream globals->util = makeUtil( MPPARM(mpool) &state->env, jutil, globals->gi, globals ); globals->jniutil = makeJNIUtil( MPPARM(mpool) &state->env, jniu ); - makeDicts( MPPARM(mpool) env, globals->jniutil, &dicts, jdicts, jdictNames, - jlang ); + makeDicts( MPPARM(mpool) env, globals->jniutil, &dict, &dicts, jdicts, + jdictNames, jlang ); globals->dctx = makeDraw( MPPARM(mpool) &state->env, jdraw ); globals->xportProcs = makeXportProcs( MPPARM(mpool) &state->env, jprocs ); @@ -458,7 +465,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream CommonPrefs cp; loadCommonPrefs( env, &cp, jcp ); result = game_makeFromStream( MPPARM(mpool) stream, &state->game, - globals->gi, NULL, &dicts, + globals->gi, dict, &dicts, globals->util, globals->dctx, &cp, globals->xportProcs ); stream_destroy( stream ); @@ -472,6 +479,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream destroyDraw( &globals->dctx ); destroyXportProcs( &globals->xportProcs ); destroyDicts( &dicts ); + dict_destroy( dict ); destroyUtil( &globals->util ); destroyJNIUtil( &globals->jniutil ); destroyGI( MPPARM(mpool) &globals->gi );