From 17863a45b6aa508008a02f4e60b9c40df32f00ce Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 24 Feb 2015 17:59:53 +0000 Subject: [PATCH] Workaround for problems on Android when the OS reuses a posix thread for the openGL thread. --- .../native/juce_android_JNIHelpers.h | 20 ++++++++++++++----- .../juce_opengl/native/juce_OpenGL_android.h | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) 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))