Browse Source

Workaround for problems on Android when the OS reuses a posix thread for the openGL thread.

tags/2021-05-28
jules 11 years ago
parent
commit
17863a45b6
2 changed files with 16 additions and 5 deletions
  1. +15
    -5
      modules/juce_core/native/juce_android_JNIHelpers.h
  2. +1
    -0
      modules/juce_opengl/native/juce_OpenGL_android.h

+ 15
- 5
modules/juce_core/native/juce_android_JNIHelpers.h View File

@@ -290,13 +290,23 @@ public:
if (android.activity != nullptr) if (android.activity != nullptr)
{ {
jvm->DetachCurrentThread(); jvm->DetachCurrentThread();
removeCurrentThreadFromCache();
}
}
void removeCurrentThreadFromCache()
{
const pthread_t thisThread = pthread_self();
const pthread_t thisThread = pthread_self();
SpinLock::ScopedLockType sl (addRemoveLock);
SpinLock::ScopedLockType sl (addRemoveLock);
for (int i = 0; i < maxThreads; ++i)
if (threads[i] == thisThread)
threads[i] = 0;
for (int i = 0; i < maxThreads; ++i)
{
if (threads[i] == thisThread)
{
threads[i] = 0;
envs[i] = nullptr;
}
} }
} }


+ 1
- 0
modules/juce_opengl/native/juce_OpenGL_android.h View File

@@ -161,6 +161,7 @@ bool OpenGLHelpers::isContextActive()
JUCE_JNI_CALLBACK (GL_VIEW_CLASS_NAME, contextCreated, void, (JNIEnv* env, jobject view)) JUCE_JNI_CALLBACK (GL_VIEW_CLASS_NAME, contextCreated, void, (JNIEnv* env, jobject view))
{ {
threadLocalJNIEnvHolder.removeCurrentThreadFromCache();
threadLocalJNIEnvHolder.getOrAttach(); threadLocalJNIEnvHolder.getOrAttach();
if (OpenGLContext::NativeContext* const context = OpenGLContext::NativeContext::findContextFor (env, view)) if (OpenGLContext::NativeContext* const context = OpenGLContext::NativeContext::findContextFor (env, view))


Loading…
Cancel
Save