mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Android: Fixed an OpenGL crash that would occur due to failing to get a pointer to the native window
This commit is contained in:
parent
5f834225e0
commit
6894e04356
6 changed files with 49 additions and 14 deletions
|
|
@ -88,7 +88,7 @@ public:
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
void initialiseOnRenderThread (OpenGLContext& aContext)
|
||||
bool initialiseOnRenderThread (OpenGLContext& aContext)
|
||||
{
|
||||
jassert (hasInitialised);
|
||||
|
||||
|
|
@ -100,9 +100,25 @@ public:
|
|||
// get a pointer to the native window
|
||||
ANativeWindow* window = nullptr;
|
||||
if (jobject jSurface = env->CallObjectMethod (surfaceView.get(), NativeSurfaceView.getNativeSurface))
|
||||
window = ANativeWindow_fromSurface (env, jSurface);
|
||||
{
|
||||
window = ANativeWindow_fromSurface(env, jSurface);
|
||||
|
||||
jassert (window != nullptr);
|
||||
// if we didn't succeed the first time, wait 25ms and try again
|
||||
if (window == nullptr)
|
||||
{
|
||||
Thread::sleep (25);
|
||||
window = ANativeWindow_fromSurface (env, jSurface);
|
||||
}
|
||||
}
|
||||
|
||||
if (window == nullptr)
|
||||
{
|
||||
// failed to get a pointer to the native window after second try so
|
||||
// bail out
|
||||
jassertfalse;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// create the surface
|
||||
surface = eglCreateWindowSurface(display, config, window, 0);
|
||||
|
|
@ -116,6 +132,8 @@ public:
|
|||
jassert (context != EGL_NO_CONTEXT);
|
||||
|
||||
juceContext = &aContext;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void shutdownOnRenderThread()
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ public:
|
|||
[view release];
|
||||
}
|
||||
|
||||
void initialiseOnRenderThread (OpenGLContext&) {}
|
||||
bool initialiseOnRenderThread (OpenGLContext&) { return true; }
|
||||
|
||||
void shutdownOnRenderThread()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -142,12 +142,14 @@ public:
|
|||
XWindowSystem::getInstance()->displayUnref();
|
||||
}
|
||||
|
||||
void initialiseOnRenderThread (OpenGLContext& c)
|
||||
bool initialiseOnRenderThread (OpenGLContext& c)
|
||||
{
|
||||
ScopedXLock xlock (display);
|
||||
renderContext = glXCreateContext (display, bestVisual, (GLXContext) contextToShareWith, GL_TRUE);
|
||||
c.makeActive();
|
||||
context = &c;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void shutdownOnRenderThread()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -89,7 +89,12 @@ public:
|
|||
releaseDC();
|
||||
}
|
||||
|
||||
void initialiseOnRenderThread (OpenGLContext& c) { context = &c; }
|
||||
bool initialiseOnRenderThread (OpenGLContext& c)
|
||||
{
|
||||
context = &c;
|
||||
return true;
|
||||
}
|
||||
|
||||
void shutdownOnRenderThread() { deactivateCurrentContext(); context = nullptr; }
|
||||
|
||||
static void deactivateCurrentContext() { wglMakeCurrent (0, 0); }
|
||||
|
|
|
|||
|
|
@ -438,7 +438,13 @@ public:
|
|||
} while (! mmLock.retryLock());
|
||||
}
|
||||
|
||||
initialiseOnThread();
|
||||
if (! initialiseOnThread())
|
||||
{
|
||||
hasInitialised = false;
|
||||
|
||||
return ThreadPoolJob::jobHasFinished;
|
||||
}
|
||||
|
||||
hasInitialised = true;
|
||||
|
||||
while (! shouldExit())
|
||||
|
|
@ -468,7 +474,7 @@ public:
|
|||
return ThreadPoolJob::jobHasFinished;
|
||||
}
|
||||
|
||||
void initialiseOnThread()
|
||||
bool initialiseOnThread()
|
||||
{
|
||||
// On android, this can get called twice, so drop any previous state..
|
||||
associatedObjectNames.clear();
|
||||
|
|
@ -476,7 +482,9 @@ public:
|
|||
cachedImageFrameBuffer.release();
|
||||
|
||||
context.makeActive();
|
||||
nativeContext->initialiseOnRenderThread (context);
|
||||
|
||||
if (! nativeContext->initialiseOnRenderThread (context))
|
||||
return false;
|
||||
|
||||
#if JUCE_ANDROID
|
||||
// On android the context may be created in initialiseOnRenderThread
|
||||
|
|
@ -506,6 +514,8 @@ public:
|
|||
|
||||
if (context.renderer != nullptr)
|
||||
context.renderer->newOpenGLContextCreated();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void shutdownOnThread()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue