src/core/android/SDL_android.c
changeset 12563 db549862a09a
parent 12556 9b2e48b381db
child 12564 04ec6bb43c4e
equal deleted inserted replaced
12562:d21956a01eed 12563:db549862a09a
   329 JNIEnv* Android_JNI_GetEnv(void)
   329 JNIEnv* Android_JNI_GetEnv(void)
   330 {
   330 {
   331     /* Get JNIEnv from the Thread local storage */
   331     /* Get JNIEnv from the Thread local storage */
   332     JNIEnv *env = pthread_getspecific(mThreadKey);
   332     JNIEnv *env = pthread_getspecific(mThreadKey);
   333     if (env == NULL) {
   333     if (env == NULL) {
   334         __android_log_print(ANDROID_LOG_ERROR, "SDL", "JNIEnv is NULL. Call Android_JNI_SetupThread() first.");
   334         /* If it fails, try to attach ! (e.g the thread isn't * created with SDL_CreateThread() */
       
   335         int status;
       
   336 
       
   337         /* There should be a JVM */
       
   338         if (mJavaVM == NULL) {
       
   339             __android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed, there is no JavaVM");
       
   340             return 0;
       
   341         }
       
   342 
       
   343         /* Attach the current thread to the JVM and get a JNIEnv.
       
   344          * It will be detached by pthread_create destructor 'Android_JNI_ThreadDestroyed' */
       
   345         status = (*mJavaVM)->AttachCurrentThread(mJavaVM, &env, NULL);
       
   346         if (status < 0) {
       
   347             __android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed to attach current thread (err=%d)", status);
       
   348             return NULL;
       
   349         }
       
   350 
       
   351         /* Save JNIEnv into the Thread local storage */
       
   352         if (Android_JNI_SetEnv(env) < 0) {
       
   353             return NULL;
       
   354         }
   335     }
   355     }
   336 
   356 
   337     return env;
   357     return env;
   338 }
   358 }
   339 
   359