Permalink
Browse files

Android: Fix race condition on lock/unlock.

This might be related to the recreate from bad orientation - sometimes, it
was pause/resuming pretty quick, which would get stuck waiting for a join.
  • Loading branch information...
unknownbrackets committed Dec 4, 2017
1 parent 7f5ba21 commit 9c046d75183ca7a72f167c524f6e6bdd1d2245c0
Showing with 13 additions and 8 deletions.
  1. +12 −7 android/jni/app-android.cpp
  2. +1 −1 android/src/org/ppsspp/ppsspp/NativeActivity.java
@@ -1101,6 +1101,10 @@ static void ProcessFrameCommands(JNIEnv *env) {
}
extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(JNIEnv *env, jobject obj, jobject _surf) {
exitRenderLoop = false;
// This is up here to prevent race conditions, in case we pause during init.
renderLoopRunning = true;
ANativeWindow *wnd = ANativeWindow_fromSurface(env, _surf);
// Need to get the local JNI env for the graphics thread. Used later in draw_text_android.
@@ -1113,6 +1117,7 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
if (wnd == nullptr) {
ELOG("Error: Surface is null.");
renderLoopRunning = false;
return false;
}
@@ -1131,7 +1136,7 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
if (!graphicsContext->Init(wnd, desiredBackbufferSizeX, desiredBackbufferSizeY, backbuffer_format, androidVersion)) {
ELOG("Failed to initialize graphics context.");
if (vulkan && tries < 2) {
if (!exitRenderLoop && (vulkan && tries < 2)) {
ILOG("Trying again, this time with OpenGL.");
g_Config.iGPUBackend = GPU_BACKEND_OPENGL;
SetGPUBackend((GPUBackend)g_Config.iGPUBackend); // Wait, why do we need a separate enum here?
@@ -1141,10 +1146,11 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
delete graphicsContext;
graphicsContext = nullptr;
renderLoopRunning = false;
return false;
}
if (!renderer_inited) {
if (!exitRenderLoop && !renderer_inited) {
NativeInitGraphics(graphicsContext);
if (renderer_ever_inited) {
NativeDeviceRestore();
@@ -1153,9 +1159,6 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
renderer_ever_inited = true;
}
exitRenderLoop = false;
renderLoopRunning = true;
while (!exitRenderLoop) {
static bool hasSetThreadName = false;
if (!hasSetThreadName) {
@@ -1174,9 +1177,11 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
}
ILOG("Leaving EGL/Vulkan render loop.");
g_gameInfoCache->WorkQueue()->Flush();
if (g_gameInfoCache)
g_gameInfoCache->WorkQueue()->Flush();
NativeDeviceLost();
if (renderer_inited)
NativeDeviceLost();
renderer_inited = false;
ILOG("Shutting down graphics context.");
@@ -432,7 +432,7 @@ public void run() {
// Start emulation using the provided Surface.
if (!runEGLRenderLoop(mSurface)) {
// Shouldn't happen.
Log.e(TAG, "Failed to start up OpenGL");
Log.e(TAG, "Failed to start up OpenGL/Vulkan");
}
Log.i(TAG, "Left the render loop: " + mSurface);
}

0 comments on commit 9c046d7

Please sign in to comment.