mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-23 07:27:22 +01:00
add env to map immediately, in initGame()
I'm seeing an assertion failure in cleanup that could be explained by the cleanup happening when initGame() has been called but no subsequent jni method that would have added the env to the map. So let's add it immediately so that can't happen.
This commit is contained in:
parent
bd631db7d2
commit
273e66fd07
3 changed files with 17 additions and 17 deletions
|
@ -113,8 +113,8 @@ public class XWApp extends Application implements LifecycleObserver {
|
|||
@Override
|
||||
public void onTerminate()
|
||||
{
|
||||
Log.i( TAG, "onTerminate() called" );
|
||||
XwJNI.cleanGlobals();
|
||||
Log.d( TAG, "onTerminate() called" );
|
||||
XwJNI.cleanGlobalsEmu();
|
||||
super.onTerminate();
|
||||
}
|
||||
|
||||
|
|
|
@ -114,16 +114,21 @@ public class XwJNI {
|
|||
m_ptr = initGlobals( new DUtilCtxt(), JNIUtilsImpl.get() );
|
||||
}
|
||||
|
||||
public static void cleanGlobals()
|
||||
public static void cleanGlobalsEmu()
|
||||
{
|
||||
cleanGlobals();
|
||||
}
|
||||
|
||||
private static void cleanGlobals()
|
||||
{
|
||||
synchronized( XwJNI.class ) { // let's be safe here
|
||||
XwJNI jni = getJNI();
|
||||
cleanGlobals( jni.m_ptr );
|
||||
cleanGlobals( jni.m_ptr ); // tests for 0
|
||||
jni.m_ptr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
@Override
|
||||
public void finalize() throws java.lang.Throwable
|
||||
{
|
||||
cleanGlobals( m_ptr );
|
||||
|
@ -178,10 +183,10 @@ public class XwJNI {
|
|||
public static native String comms_getUUID();
|
||||
|
||||
// Game methods
|
||||
private static GamePtr initJNI( long rowid )
|
||||
private static GamePtr initGameJNI( long rowid )
|
||||
{
|
||||
int seed = Utils.nextRandomInt();
|
||||
int ptr = initJNI( getJNI().m_ptr, seed );
|
||||
int ptr = initGameJNI( getJNI().m_ptr, seed );
|
||||
GamePtr result = 0 == ptr ? null : new GamePtr( ptr, rowid );
|
||||
return result;
|
||||
}
|
||||
|
@ -194,7 +199,7 @@ public class XwJNI {
|
|||
CommonPrefs cp, TransportProcs procs )
|
||||
|
||||
{
|
||||
GamePtr gamePtr = initJNI( rowid );
|
||||
GamePtr gamePtr = initGameJNI( rowid );
|
||||
if ( game_makeFromStream( gamePtr, stream, gi, dictNames, dictBytes,
|
||||
dictPaths, langName, util, draw,
|
||||
cp, procs ) ) {
|
||||
|
@ -211,7 +216,7 @@ public class XwJNI {
|
|||
String[] dictPaths, String langName, UtilCtxt util,
|
||||
DrawCtx draw, CommonPrefs cp, TransportProcs procs )
|
||||
{
|
||||
GamePtr gamePtr = initJNI( 0 );
|
||||
GamePtr gamePtr = initGameJNI( 0 );
|
||||
game_makeNewGame( gamePtr, gi, dictNames, dictBytes, dictPaths,
|
||||
langName, util, draw, cp, procs );
|
||||
return gamePtr.retain();
|
||||
|
@ -513,7 +518,7 @@ public class XwJNI {
|
|||
private static native byte[] nli_to_stream( int jniState, NetLaunchInfo nli );
|
||||
private static native void nli_from_stream( int jniState, NetLaunchInfo nli,
|
||||
byte[] stream );
|
||||
private static native int initJNI( int jniState, int seed );
|
||||
private static native int initGameJNI( int jniState, int seed );
|
||||
private static native void envDone( int globals );
|
||||
private static native void dict_ref( int dictPtr );
|
||||
private static native void dict_unref( int dictPtr );
|
||||
|
|
|
@ -916,26 +916,21 @@ struct _JNIState {
|
|||
} \
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_initJNI
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_initGameJNI
|
||||
( JNIEnv* env, jclass C, int jniGlobalPtr, jint seed )
|
||||
{
|
||||
/* Why am I doing this twice? */
|
||||
/* struct timeval tv; */
|
||||
/* gettimeofday( &tv, NULL ); */
|
||||
/* srandom( tv.tv_sec ); */
|
||||
#ifdef MEM_DEBUG
|
||||
MemPoolCtx* mpool = ((JNIGlobalState*)jniGlobalPtr)->mpool;
|
||||
#endif
|
||||
JNIState* state = (JNIState*)XP_CALLOC( mpool, sizeof(*state) );
|
||||
state->globalJNI = (JNIGlobalState*)jniGlobalPtr;
|
||||
map_thread( &state->globalJNI->ti, env );
|
||||
AndGameGlobals* globals = &state->globals;
|
||||
globals->dutil = state->globalJNI->dutil;
|
||||
globals->state = (JNIState*)state;
|
||||
MPASSIGN( state->mpool, mpool );
|
||||
globals->vtMgr = make_vtablemgr(MPPARM_NOCOMMA(mpool));
|
||||
|
||||
/* pthread_mutex_init( &state->msgMutex, NULL ); */
|
||||
|
||||
/* XP_LOGF( "%s: initing srand with %d", __func__, seed ); */
|
||||
srandom( seed );
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue