don't crash on null dctxt

This commit is contained in:
Eric House 2013-10-31 06:35:23 -07:00
parent 88af10552e
commit 3858893ab2
2 changed files with 24 additions and 17 deletions

View file

@ -644,21 +644,23 @@ makeDraw( MPFORMAL JNIEnv** envp, jobject jdraw )
void
destroyDraw( DrawCtx** dctx )
{
AndDraw* draw = (AndDraw*)*dctx;
JNIEnv* env = *draw->env;
if ( NULL != draw->jdraw ) {
(*env)->DeleteGlobalRef( env, draw->jdraw );
}
int ii;
for ( ii = 0; ii < JCACHE_COUNT; ++ii ) {
jobject jobj = draw->jCache[ii];
if ( !!jobj ) {
(*env)->DeleteGlobalRef( env, jobj );
if ( !!*dctx ) {
AndDraw* draw = (AndDraw*)*dctx;
JNIEnv* env = *draw->env;
if ( NULL != draw->jdraw ) {
(*env)->DeleteGlobalRef( env, draw->jdraw );
}
}
XP_FREE( draw->mpool, draw->vtable );
XP_FREE( draw->mpool, draw );
*dctx = NULL;
int ii;
for ( ii = 0; ii < JCACHE_COUNT; ++ii ) {
jobject jobj = draw->jCache[ii];
if ( !!jobj ) {
(*env)->DeleteGlobalRef( env, jobj );
}
}
XP_FREE( draw->mpool, draw->vtable );
XP_FREE( draw->mpool, draw );
*dctx = NULL;
}
}

View file

@ -417,7 +417,10 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeNewGame
globals->util = makeUtil( MPPARM(mpool) &state->env, j_util, gi,
globals );
globals->jniutil = makeJNIUtil( MPPARM(mpool) &state->env, jniu );
DrawCtx* dctx = makeDraw( MPPARM(mpool) &state->env, j_draw );
DrawCtx* dctx = NULL;
if ( !!j_draw ) {
dctx = makeDraw( MPPARM(mpool) &state->env, j_draw );
}
globals->dctx = dctx;
globals->xportProcs = makeXportProcs( MPPARM(mpool) &state->env, j_procs );
CommonPrefs cp;
@ -486,7 +489,9 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1makeFromStream
globals->jniutil = makeJNIUtil( MPPARM(mpool) &state->env, jniu );
makeDicts( MPPARM(mpool) env, globals->jniutil, &dict, &dicts, jdictNames,
jdicts, jpaths, jlang );
globals->dctx = makeDraw( MPPARM(mpool) &state->env, jdraw );
if ( !!jdraw ) {
globals->dctx = makeDraw( MPPARM(mpool) &state->env, jdraw );
}
globals->xportProcs = makeXportProcs( MPPARM(mpool) &state->env, jprocs );
XWStreamCtxt* stream = streamFromJStream( MPPARM(mpool) env,