diff --git a/modules/juce_core/native/juce_android_JNIHelpers.h b/modules/juce_core/native/juce_android_JNIHelpers.h index 88869991bb..0c35c63dd2 100644 --- a/modules/juce_core/native/juce_android_JNIHelpers.h +++ b/modules/juce_core/native/juce_android_JNIHelpers.h @@ -290,13 +290,23 @@ public: if (android.activity != nullptr) { jvm->DetachCurrentThread(); + removeCurrentThreadFromCache(); + } + } - const pthread_t thisThread = pthread_self(); + void removeCurrentThreadFromCache() + { + const pthread_t thisThread = pthread_self(); - SpinLock::ScopedLockType sl (addRemoveLock); - for (int i = 0; i < maxThreads; ++i) - if (threads[i] == thisThread) - threads[i] = 0; + SpinLock::ScopedLockType sl (addRemoveLock); + + for (int i = 0; i < maxThreads; ++i) + { + if (threads[i] == thisThread) + { + threads[i] = 0; + envs[i] = nullptr; + } } } diff --git a/modules/juce_opengl/native/juce_OpenGL_android.h b/modules/juce_opengl/native/juce_OpenGL_android.h index 84983c766f..46ef9713da 100644 --- a/modules/juce_opengl/native/juce_OpenGL_android.h +++ b/modules/juce_opengl/native/juce_OpenGL_android.h @@ -161,6 +161,7 @@ bool OpenGLHelpers::isContextActive() JUCE_JNI_CALLBACK (GL_VIEW_CLASS_NAME, contextCreated, void, (JNIEnv* env, jobject view)) { + threadLocalJNIEnvHolder.removeCurrentThreadFromCache(); threadLocalJNIEnvHolder.getOrAttach(); if (OpenGLContext::NativeContext* const context = OpenGLContext::NativeContext::findContextFor (env, view))