android: native: Ensure shutdown on exit.

This commit is contained in:
bunnei 2020-04-26 04:03:21 -04:00
parent eab2e7ec12
commit 2df0d04d2e

View File

@ -90,10 +90,25 @@ static int AlertPromptButton() {
static Camera::NDK::Factory* g_ndk_factory{}; static Camera::NDK::Factory* g_ndk_factory{};
static void TryShutdown() {
if (!window) {
return;
}
window->StopPresenting();
window->DoneCurrent();
Core::System::GetInstance().Shutdown();
window.reset();
InputManager::Shutdown();
MicroProfileShutdown();
}
static Core::System::ResultStatus RunCitra(const std::string& filepath) { static Core::System::ResultStatus RunCitra(const std::string& filepath) {
// Citra core only supports a single running instance // Citra core only supports a single running instance
std::lock_guard<std::mutex> lock(running_mutex); std::lock_guard<std::mutex> lock(running_mutex);
TryShutdown();
LOG_INFO(Frontend, "Citra is Starting"); LOG_INFO(Frontend, "Citra is Starting");
MicroProfileOnThreadCreate("EmuThread"); MicroProfileOnThreadCreate("EmuThread");
@ -136,6 +151,9 @@ static Core::System::ResultStatus RunCitra(const std::string& filepath) {
pause_emulation = false; pause_emulation = false;
window->StartPresenting(); window->StartPresenting();
SCOPE_EXIT({TryShutdown();});
while (is_running) { while (is_running) {
if (!pause_emulation) { if (!pause_emulation) {
system.RunLoop(); system.RunLoop();
@ -149,12 +167,6 @@ static Core::System::ResultStatus RunCitra(const std::string& filepath) {
running_cv.wait(pause_lock, [] { return !pause_emulation || !is_running; }); running_cv.wait(pause_lock, [] { return !pause_emulation || !is_running; });
} }
} }
window->StopPresenting();
system.Shutdown();
window.reset();
InputManager::Shutdown();
MicroProfileShutdown();
return Core::System::ResultStatus::Success; return Core::System::ResultStatus::Success;
} }