Permalink
Browse files

ae-bridge: Delay unloading libraries to address crash on exit.

  • Loading branch information...
littleguy77 committed Jan 25, 2015
1 parent 4cc1cb8 commit 1b3689255633b0d1b0f0a1a8310def6cc7c53b2d
Showing with 7 additions and 16 deletions.
  1. +7 −16 jni/ae-bridge/ae_exports.cpp
@@ -80,7 +80,12 @@ extern jint JNI_OnLoad(JavaVM* vm, void* reserved)
extern "C" DECLSPEC void SDLCALL Java_paulscode_android_mupen64plusae_jni_NativeExports_loadLibraries(JNIEnv* env, jclass cls, jstring jlibPath)
{
LOGI("Loading native libraries");
// Unload the libraries to ensure that static variables are re-initialized next time
LOGI("Unloading native libraries");
if (handleFront) dlclose(handleFront);
if (handleCore) dlclose(handleCore);
if (handleSDL) dlclose(handleSDL);
if (handleAEI) dlclose(handleAEI);
// Construct the library paths
const char *libPath = env->GetStringUTFChars(jlibPath, 0);
@@ -95,6 +100,7 @@ extern "C" DECLSPEC void SDLCALL Java_paulscode_android_mupen64plusae_jni_Native
env->ReleaseStringUTFChars(jlibPath, libPath);
// Open shared libraries
LOGI("Loading native libraries");
handleAEI = dlopen(pathAEI, RTLD_NOW);
handleSDL = dlopen(pathSDL, RTLD_NOW);
handleCore = dlopen(pathCore, RTLD_NOW);
@@ -131,28 +137,13 @@ extern "C" DECLSPEC void SDLCALL Java_paulscode_android_mupen64plusae_jni_Native
extern "C" DECLSPEC void SDLCALL Java_paulscode_android_mupen64plusae_jni_NativeExports_unloadLibraries(JNIEnv* env, jclass cls)
{
// Unload the libraries to ensure that static variables are re-initialized next time
LOGI("Unloading native libraries");
// Nullify function pointers
aeiInit = NULL;
sdlInit = NULL;
sdlSetScreen = NULL;
sdlMainReady = NULL;
coreDoCommand = NULL;
frontMain = NULL;
// Close shared libraries
if (handleFront) dlclose(handleFront);
if (handleCore) dlclose(handleCore);
if (handleSDL) dlclose(handleSDL);
if (handleAEI) dlclose(handleAEI);
// Nullify handles
handleFront = NULL;
handleCore = NULL;
handleSDL = NULL;
handleAEI = NULL;
}
extern "C" DECLSPEC jint SDLCALL Java_paulscode_android_mupen64plusae_jni_NativeExports_emuStart(JNIEnv* env, jclass cls, jstring juserDataPath, jstring juserCachePath, jobjectArray jargv)

0 comments on commit 1b36892

Please sign in to comment.