Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Ensure shutdown waits for render #14134

Merged
merged 1 commit into from
Feb 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,9 @@ void RenderOverlays(UIContext *dc, void *userdata) {
}

void NativeRender(GraphicsContext *graphicsContext) {
_assert_(graphicsContext != nullptr);
_assert_(screenManager != nullptr);

g_GameManager.Update();

if (GetUIState() != UISTATE_INGAME) {
Expand Down
26 changes: 17 additions & 9 deletions android/jni/app-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ static float dp_yscale = 1.0f;

static bool renderer_inited = false;
static bool sustainedPerfSupported = false;
static std::mutex renderLock;

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

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

inputBoxCallbacks.clear();
NativeShutdown();
VFSShutdown();
{
std::lock_guard<std::mutex> guard(renderLock);
inputBoxCallbacks.clear();
NativeShutdown();
VFSShutdown();
}

std::lock_guard<std::mutex> guard(frameCommandLock);
while (frameCommands.size())
frameCommands.pop();
INFO_LOG(SYSTEM, "NativeApp.shutdown() -- end");
Expand Down Expand Up @@ -929,10 +936,14 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendInputBox(JNIEnv *en
NativeInputBoxReceived(entry->second, result, value);
}

void UpdateRunLoopAndroid(JNIEnv *env) {
void LockedNativeUpdateRender() {
std::lock_guard<std::mutex> renderGuard(renderLock);
NativeUpdate();

NativeRender(graphicsContext);
}

void UpdateRunLoopAndroid(JNIEnv *env) {
LockedNativeUpdateRender();

std::lock_guard<std::mutex> guard(frameCommandLock);
if (!nativeActivity) {
Expand Down Expand Up @@ -1352,10 +1363,7 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
}
} else {
while (!exitRenderLoop) {
NativeUpdate();

NativeRender(graphicsContext);

LockedNativeUpdateRender();
graphicsContext->SwapBuffers();

ProcessFrameCommands(env);
Expand Down