diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 2160536fac..ffe7e411b6 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -688,7 +688,7 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init EARLY_LOG("NativeApp.init() -- begin"); PROFILE_INIT(); - std::lock_guard guard(renderLock); // Note: This is held for the rest of this function - intended? and even necessary? + std::lock_guard guard(renderLock); renderer_inited = false; exitRenderLoop = false; androidVersion = jAndroidVersion; @@ -874,8 +874,13 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_pause(JNIEnv *, jclass) { extern "C" void Java_org_ppsspp_ppsspp_NativeApp_shutdown(JNIEnv *, jclass) { INFO_LOG(SYSTEM, "NativeApp.shutdown() -- begin"); + if (renderer_inited && useCPUThread && graphicsContext) { // Only used in Java EGL path. + + // We can't lock renderLock here because the emu thread will be in NativeFrame + // which locks renderLock already, and only gets out once we call ThreadFrame() + // in a loop before, to empty the queue. EmuThreadStop("shutdown"); INFO_LOG(SYSTEM, "BeginAndroidShutdown"); graphicsContext->BeginAndroidShutdown(); @@ -893,18 +898,19 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_shutdown(JNIEnv *, jclass) { EmuThreadJoin(); } - if (graphicsContext) { - INFO_LOG(G3D, "Shutting down renderer"); - graphicsContext->Shutdown(); - delete graphicsContext; - graphicsContext = nullptr; - renderer_inited = false; - } else { - INFO_LOG(G3D, "Not shutting down renderer - not initialized"); - } - { std::lock_guard guard(renderLock); + + if (graphicsContext) { + INFO_LOG(G3D, "Shutting down renderer"); + graphicsContext->Shutdown(); + delete graphicsContext; + graphicsContext = nullptr; + renderer_inited = false; + } else { + INFO_LOG(G3D, "Not shutting down renderer - not initialized"); + } + NativeShutdown(); g_VFS.Clear(); } diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 831cc16d76..4f6cc78353 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -751,16 +751,21 @@ public abstract class NativeActivity extends Activity { super.onDestroy(); Log.i(TAG, "onDestroy"); if (javaGL) { - if (nativeRenderer != null && nativeRenderer.isRenderingFrame()) { - Log.i(TAG, "Waiting for renderer to finish."); - int tries = 200; - do { - try { - Thread.sleep(10); - } catch (InterruptedException e) { - } - tries--; - } while (nativeRenderer.isRenderingFrame() && tries > 0); + if (nativeRenderer != null) { + if (nativeRenderer.isRenderingFrame()) { + Log.i(TAG, "Waiting for renderer to finish."); + int tries = 200; + do { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + } + tries--; + } while (nativeRenderer.isRenderingFrame() && tries > 0); + } else { + Log.i(TAG, "nativerenderer done."); + nativeRenderer = null; + } } mGLSurfaceView.onDestroy(); mGLSurfaceView = null;