I spend about hour to find out why manually created thread with pthreads (not SDL_CreateThread) library is crashing after reading files from apk.
Why SDL doesn’t associate JNIENV automatically with current thread when Android_JNI_GetEnv() was called?
please review this patch, it makes all user created threads compatible with SDL
I moved pthread_setspecific(mThreadKey, (void*) env) from Android_JNI_SetupThread to Android_JNI_GetEnv
diff -r e1f2a85d9dda src/core/android/SDL_android.c
— a/src/core/android/SDL_android.c Thu Nov 28 02:31:32 2013 -0800
+++ b/src/core/android/SDL_android.c Wed Dec 04 00:35:35 2013 +0600
@@ -477,6 +477,7 @@
JNIEnv *env;
int status = (*mJavaVM)->AttachCurrentThread(mJavaVM, &env, NULL);
- pthread_setspecific(mThreadKey, (void*) env);
if(status < 0) {
LOGE(“failed to attach current thread”);
return 0;
@@ -496,7 +497,7 @@
*/
JNIEnv *env = Android_JNI_GetEnv();
- pthread_setspecific(mThreadKey, (void*) env);
- //pthread_setspecific(mThreadKey, (void*) env);
return 1;
}
Here you go!
https://hg.libsdl.org/SDL/rev/3e2f230a6d62On Tue, Dec 3, 2013 at 10:41 AM, dmuratshin wrote:
I spend about hour to find out why manually created thread with pthreads
(not SDL_CreateThread) library is crashing after reading files from apk.
Why SDL doesn’t associate JNIENV automatically with current thread when
Android_JNI_GetEnv() was called?
please review this patch, it makes all user created threads compatible
with SDL
I moved pthread_setspecific(mThreadKey, (void*) env) from
Android_JNI_SetupThread to Android_JNI_GetEnv
diff -r e1f2a85d9dda src/core/android/SDL_android.c
— a/src/core/android/SDL_android.c Thu Nov 28 02:31:32 2013 -0800
+++ b/src/core/android/SDL_android.c Wed Dec 04 00:35:35 2013 +0600
@@ -477,6 +477,7 @@
JNIEnv *env;
int status = (*mJavaVM)->AttachCurrentThread(mJavaVM, &env, NULL);
- pthread_setspecific(mThreadKey, (void*) env);
if(status < 0) {
LOGE(“failed to attach current thread”);
return 0;
@@ -496,7 +497,7 @@
- (except for some lost CPU cycles)
*/
JNIEnv *env = Android_JNI_GetEnv();
- pthread_setspecific(mThreadKey, (void*) env);
- //pthread_setspecific(mThreadKey, (void*) env);
return 1;
}
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org