Browse Source

Android: Fixed an OpenGL crash that would occur due to failing to get a pointer to the native window

tags/2021-05-28
ed 8 years ago
parent
commit
6894e04356
6 changed files with 49 additions and 14 deletions
  1. +21
    -3
      modules/juce_opengl/native/juce_OpenGL_android.h
  2. +1
    -1
      modules/juce_opengl/native/juce_OpenGL_ios.h
  3. +3
    -1
      modules/juce_opengl/native/juce_OpenGL_linux_X11.h
  4. +5
    -5
      modules/juce_opengl/native/juce_OpenGL_osx.h
  5. +6
    -1
      modules/juce_opengl/native/juce_OpenGL_win32.h
  6. +13
    -3
      modules/juce_opengl/opengl/juce_OpenGLContext.cpp

+ 21
- 3
modules/juce_opengl/native/juce_OpenGL_android.h View File

@@ -88,7 +88,7 @@ public:
} }
//============================================================================== //==============================================================================
void initialiseOnRenderThread (OpenGLContext& aContext)
bool initialiseOnRenderThread (OpenGLContext& aContext)
{ {
jassert (hasInitialised); jassert (hasInitialised);
@@ -100,9 +100,25 @@ public:
// get a pointer to the native window // get a pointer to the native window
ANativeWindow* window = nullptr; ANativeWindow* window = nullptr;
if (jobject jSurface = env->CallObjectMethod (surfaceView.get(), NativeSurfaceView.getNativeSurface)) if (jobject jSurface = env->CallObjectMethod (surfaceView.get(), NativeSurfaceView.getNativeSurface))
window = ANativeWindow_fromSurface (env, jSurface);
{
window = ANativeWindow_fromSurface(env, jSurface);
// if we didn't succeed the first time, wait 25ms and try again
if (window == nullptr)
{
Thread::sleep (25);
window = ANativeWindow_fromSurface (env, jSurface);
}
}
jassert (window != nullptr);
if (window == nullptr)
{
// failed to get a pointer to the native window after second try so
// bail out
jassertfalse;
return false;
}
// create the surface // create the surface
surface = eglCreateWindowSurface(display, config, window, 0); surface = eglCreateWindowSurface(display, config, window, 0);
@@ -116,6 +132,8 @@ public:
jassert (context != EGL_NO_CONTEXT); jassert (context != EGL_NO_CONTEXT);
juceContext = &aContext; juceContext = &aContext;
return true;
} }
void shutdownOnRenderThread() void shutdownOnRenderThread()


+ 1
- 1
modules/juce_opengl/native/juce_OpenGL_ios.h View File

@@ -113,7 +113,7 @@ public:
[view release]; [view release];
} }
void initialiseOnRenderThread (OpenGLContext&) {}
bool initialiseOnRenderThread (OpenGLContext&) { return true; }
void shutdownOnRenderThread() void shutdownOnRenderThread()
{ {


+ 3
- 1
modules/juce_opengl/native/juce_OpenGL_linux_X11.h View File

@@ -142,12 +142,14 @@ public:
XWindowSystem::getInstance()->displayUnref(); XWindowSystem::getInstance()->displayUnref();
} }
void initialiseOnRenderThread (OpenGLContext& c)
bool initialiseOnRenderThread (OpenGLContext& c)
{ {
ScopedXLock xlock (display); ScopedXLock xlock (display);
renderContext = glXCreateContext (display, bestVisual, (GLXContext) contextToShareWith, GL_TRUE); renderContext = glXCreateContext (display, bestVisual, (GLXContext) contextToShareWith, GL_TRUE);
c.makeActive(); c.makeActive();
context = &c; context = &c;
return true;
} }
void shutdownOnRenderThread() void shutdownOnRenderThread()


+ 5
- 5
modules/juce_opengl/native/juce_OpenGL_osx.h View File

@@ -111,12 +111,12 @@ public:
} }
} }
void initialiseOnRenderThread (OpenGLContext&) {}
void shutdownOnRenderThread() { deactivateCurrentContext(); }
bool initialiseOnRenderThread (OpenGLContext&) { return true; }
void shutdownOnRenderThread() { deactivateCurrentContext(); }
bool createdOk() const noexcept { return getRawContext() != nullptr; }
void* getRawContext() const noexcept { return static_cast<void*> (renderContext); }
GLuint getFrameBufferID() const noexcept { return 0; }
bool createdOk() const noexcept { return getRawContext() != nullptr; }
void* getRawContext() const noexcept { return static_cast<void*> (renderContext); }
GLuint getFrameBufferID() const noexcept { return 0; }
bool makeActive() const noexcept bool makeActive() const noexcept
{ {


+ 6
- 1
modules/juce_opengl/native/juce_OpenGL_win32.h View File

@@ -89,7 +89,12 @@ public:
releaseDC(); releaseDC();
} }
void initialiseOnRenderThread (OpenGLContext& c) { context = &c; }
bool initialiseOnRenderThread (OpenGLContext& c)
{
context = &c;
return true;
}
void shutdownOnRenderThread() { deactivateCurrentContext(); context = nullptr; } void shutdownOnRenderThread() { deactivateCurrentContext(); context = nullptr; }
static void deactivateCurrentContext() { wglMakeCurrent (0, 0); } static void deactivateCurrentContext() { wglMakeCurrent (0, 0); }


+ 13
- 3
modules/juce_opengl/opengl/juce_OpenGLContext.cpp View File

@@ -438,7 +438,13 @@ public:
} while (! mmLock.retryLock()); } while (! mmLock.retryLock());
} }
initialiseOnThread();
if (! initialiseOnThread())
{
hasInitialised = false;
return ThreadPoolJob::jobHasFinished;
}
hasInitialised = true; hasInitialised = true;
while (! shouldExit()) while (! shouldExit())
@@ -468,7 +474,7 @@ public:
return ThreadPoolJob::jobHasFinished; return ThreadPoolJob::jobHasFinished;
} }
void initialiseOnThread()
bool initialiseOnThread()
{ {
// On android, this can get called twice, so drop any previous state.. // On android, this can get called twice, so drop any previous state..
associatedObjectNames.clear(); associatedObjectNames.clear();
@@ -476,7 +482,9 @@ public:
cachedImageFrameBuffer.release(); cachedImageFrameBuffer.release();
context.makeActive(); context.makeActive();
nativeContext->initialiseOnRenderThread (context);
if (! nativeContext->initialiseOnRenderThread (context))
return false;
#if JUCE_ANDROID #if JUCE_ANDROID
// On android the context may be created in initialiseOnRenderThread // On android the context may be created in initialiseOnRenderThread
@@ -506,6 +514,8 @@ public:
if (context.renderer != nullptr) if (context.renderer != nullptr)
context.renderer->newOpenGLContextCreated(); context.renderer->newOpenGLContextCreated();
return true;
} }
void shutdownOnThread() void shutdownOnThread()


Loading…
Cancel
Save