Skip to content

Commit 91f84ce

Browse files
authored
Merge pull request hrydgard#14134 from unknownbrackets/android-render
Android: Ensure shutdown waits for render
2 parents f34f554 + fb7e4ac commit 91f84ce

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

UI/NativeApp.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,9 @@ void RenderOverlays(UIContext *dc, void *userdata) {
10601060
}
10611061

10621062
void NativeRender(GraphicsContext *graphicsContext) {
1063+
_assert_(graphicsContext != nullptr);
1064+
_assert_(screenManager != nullptr);
1065+
10631066
g_GameManager.Update();
10641067

10651068
if (GetUIState() != UISTATE_INGAME) {

android/jni/app-android.cpp

+17-9
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ static float dp_yscale = 1.0f;
174174

175175
static bool renderer_inited = false;
176176
static bool sustainedPerfSupported = false;
177+
static std::mutex renderLock;
177178

178179
// See NativeQueryConfig("androidJavaGL") to change this value.
179180
static bool javaGL = true;
@@ -567,6 +568,7 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init
567568
EARLY_LOG("NativeApp.init() -- begin");
568569
PROFILE_INIT();
569570

571+
std::lock_guard<std::mutex> guard(renderLock);
570572
renderer_inited = false;
571573
androidVersion = jAndroidVersion;
572574
deviceType = jdeviceType;
@@ -776,9 +778,14 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_shutdown(JNIEnv *, jclass) {
776778
INFO_LOG(G3D, "Not shutting down renderer - not initialized");
777779
}
778780

779-
inputBoxCallbacks.clear();
780-
NativeShutdown();
781-
VFSShutdown();
781+
{
782+
std::lock_guard<std::mutex> guard(renderLock);
783+
inputBoxCallbacks.clear();
784+
NativeShutdown();
785+
VFSShutdown();
786+
}
787+
788+
std::lock_guard<std::mutex> guard(frameCommandLock);
782789
while (frameCommands.size())
783790
frameCommands.pop();
784791
INFO_LOG(SYSTEM, "NativeApp.shutdown() -- end");
@@ -929,10 +936,14 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendInputBox(JNIEnv *en
929936
NativeInputBoxReceived(entry->second, result, value);
930937
}
931938

932-
void UpdateRunLoopAndroid(JNIEnv *env) {
939+
void LockedNativeUpdateRender() {
940+
std::lock_guard<std::mutex> renderGuard(renderLock);
933941
NativeUpdate();
934-
935942
NativeRender(graphicsContext);
943+
}
944+
945+
void UpdateRunLoopAndroid(JNIEnv *env) {
946+
LockedNativeUpdateRender();
936947

937948
std::lock_guard<std::mutex> guard(frameCommandLock);
938949
if (!nativeActivity) {
@@ -1352,10 +1363,7 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
13521363
}
13531364
} else {
13541365
while (!exitRenderLoop) {
1355-
NativeUpdate();
1356-
1357-
NativeRender(graphicsContext);
1358-
1366+
LockedNativeUpdateRender();
13591367
graphicsContext->SwapBuffers();
13601368

13611369
ProcessFrameCommands(env);

0 commit comments

Comments
 (0)