diff options
| -rw-r--r-- | src/android/app/src/main/jni/native.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index e1b771468..f0df6cac1 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp | |||
| @@ -96,8 +96,7 @@ public: | |||
| 96 | system.GetFileSystemController().CreateFactories(*system.GetFilesystem()); | 96 | system.GetFileSystemController().CreateFactories(*system.GetFilesystem()); |
| 97 | 97 | ||
| 98 | // Load the ROM. | 98 | // Load the ROM. |
| 99 | const Core::SystemResultStatus load_result{ | 99 | load_result = system.Load(EmulationSession::GetInstance().Window(), filepath); |
| 100 | system.Load(EmulationSession::GetInstance().Window(), filepath)}; | ||
| 101 | if (load_result != Core::SystemResultStatus::Success) { | 100 | if (load_result != Core::SystemResultStatus::Success) { |
| 102 | return load_result; | 101 | return load_result; |
| 103 | } | 102 | } |
| @@ -113,13 +112,18 @@ public: | |||
| 113 | void ShutdownEmulation() { | 112 | void ShutdownEmulation() { |
| 114 | std::scoped_lock lock(mutex); | 113 | std::scoped_lock lock(mutex); |
| 115 | 114 | ||
| 115 | is_running = false; | ||
| 116 | |||
| 116 | // Unload user input. | 117 | // Unload user input. |
| 117 | system.HIDCore().UnloadInputDevices(); | 118 | system.HIDCore().UnloadInputDevices(); |
| 118 | 119 | ||
| 119 | // Shutdown the main emulated process | 120 | // Shutdown the main emulated process |
| 120 | system.DetachDebugger(); | 121 | if (load_result == Core::SystemResultStatus::Success) { |
| 121 | system.ShutdownMainProcess(); | 122 | system.DetachDebugger(); |
| 122 | detached_tasks.WaitForAllTasks(); | 123 | system.ShutdownMainProcess(); |
| 124 | detached_tasks.WaitForAllTasks(); | ||
| 125 | load_result = Core::SystemResultStatus::ErrorNotInitialized; | ||
| 126 | } | ||
| 123 | 127 | ||
| 124 | // Tear down the render window. | 128 | // Tear down the render window. |
| 125 | window.reset(); | 129 | window.reset(); |
| @@ -174,6 +178,7 @@ private: | |||
| 174 | std::unique_ptr<EmuWindow_Android> window; | 178 | std::unique_ptr<EmuWindow_Android> window; |
| 175 | std::condition_variable_any cv; | 179 | std::condition_variable_any cv; |
| 176 | bool is_running{}; | 180 | bool is_running{}; |
| 181 | Core::SystemResultStatus load_result{Core::SystemResultStatus::ErrorNotInitialized}; | ||
| 177 | 182 | ||
| 178 | mutable std::mutex perf_stats_mutex; | 183 | mutable std::mutex perf_stats_mutex; |
| 179 | mutable std::mutex mutex; | 184 | mutable std::mutex mutex; |
| @@ -217,13 +222,14 @@ static Core::SystemResultStatus RunEmulation(const std::string& filepath) { | |||
| 217 | return Core::SystemResultStatus::ErrorLoader; | 222 | return Core::SystemResultStatus::ErrorLoader; |
| 218 | } | 223 | } |
| 219 | 224 | ||
| 225 | SCOPE_EXIT({ EmulationSession::GetInstance().ShutdownEmulation(); }); | ||
| 226 | |||
| 220 | const auto result = EmulationSession::GetInstance().InitializeEmulation(filepath); | 227 | const auto result = EmulationSession::GetInstance().InitializeEmulation(filepath); |
| 221 | if (result != Core::SystemResultStatus::Success) { | 228 | if (result != Core::SystemResultStatus::Success) { |
| 222 | return result; | 229 | return result; |
| 223 | } | 230 | } |
| 224 | 231 | ||
| 225 | EmulationSession::GetInstance().RunEmulation(); | 232 | EmulationSession::GetInstance().RunEmulation(); |
| 226 | EmulationSession::GetInstance().ShutdownEmulation(); | ||
| 227 | 233 | ||
| 228 | return Core::SystemResultStatus::Success; | 234 | return Core::SystemResultStatus::Success; |
| 229 | } | 235 | } |