diff options
author | dhewg | 2011-02-14 18:48:33 +0100 |
---|---|---|
committer | dhewg | 2011-02-14 18:58:56 +0100 |
commit | 2586e15e4ea6a365eced1888759630907b6b5870 (patch) | |
tree | 2fe7e09ec9e24a01734531e42a102c009e879825 /backends | |
parent | ea2cfc44c0ce91267aa87173cfd02eb1c69d3147 (diff) | |
download | scummvm-rg350-2586e15e4ea6a365eced1888759630907b6b5870.tar.gz scummvm-rg350-2586e15e4ea6a365eced1888759630907b6b5870.tar.bz2 scummvm-rg350-2586e15e4ea6a365eced1888759630907b6b5870.zip |
ANDROID: Fix JNI calls for the timer thread
JNI calls can happen through the timer mechanism (hence from another
thread). Attach the timer thread to the VM to prevent assert()s
Diffstat (limited to 'backends')
-rw-r--r-- | backends/platform/android/android.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index b59fc76a59..07fb1d5d98 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -102,10 +102,14 @@ static jfieldID FID_ScummVM_nativeScummVM; static jmethodID MID_Object_wait; JNIEnv* JNU_GetEnv() { - JNIEnv* env; - bool version_unsupported = - cached_jvm->GetEnv((void**)&env, JNI_VERSION_1_2); - assert(! version_unsupported); + JNIEnv* env = 0; + + jint res = cached_jvm->GetEnv((void**)&env, JNI_VERSION_1_2); + if (res != JNI_OK) { + __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "GetEnv() failed: %d", res); + abort(); + } + return env; } @@ -453,6 +457,14 @@ void* OSystem_Android::timerThreadFunc(void* arg) { OSystem_Android* system = (OSystem_Android*)arg; DefaultTimerManager* timer = (DefaultTimerManager*)(system->_timer); + JNIEnv *env = 0; + jint res = cached_jvm->AttachCurrentThread(&env, 0); + + if (res != JNI_OK) { + __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "AttachCurrentThread() failed: %d", res); + abort(); + } + struct timespec tv; tv.tv_sec = 0; tv.tv_nsec = 100 * 1000 * 1000; // 100ms @@ -462,6 +474,13 @@ void* OSystem_Android::timerThreadFunc(void* arg) { nanosleep(&tv, NULL); } + res = cached_jvm->DetachCurrentThread(); + + if (res != JNI_OK) { + __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "DetachCurrentThread() failed: %d", res); + abort(); + } + return NULL; } |