From 0276197744d5026f32a0b33e378cbf3636f97008 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 20 Feb 2023 03:19:51 -0800 Subject: [PATCH] android: jni: Ensure system is only initialized once. - Fixes likelihood that fastmem allocation succeeds. --- .../app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.java | 3 +-- .../org/yuzu/yuzu_emu/utils/DirectoryInitialization.java | 2 +- src/android/app/src/main/jni/native.cpp | 7 ++++--- src/android/app/src/main/jni/native.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.java index c09b711fdf..6f76c3f951 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.java @@ -185,8 +185,7 @@ public final class NativeLibrary { public static native boolean ReloadKeys(); - // Create the config.ini file. - public static native void CreateConfigFile(); + public static native void InitializeEmulation(); public static native int DefaultCPUCore(); diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/DirectoryInitialization.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/DirectoryInitialization.java index f922ae1837..6464c2286b 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/DirectoryInitialization.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/DirectoryInitialization.java @@ -27,7 +27,7 @@ public final class DirectoryInitialization { if (directoryState != DirectoryInitializationState.YUZU_DIRECTORIES_INITIALIZED) { initializeInternalStorage(context); - NativeLibrary.CreateConfigFile(); + NativeLibrary.InitializeEmulation(); directoryState = DirectoryInitializationState.YUZU_DIRECTORIES_INITIALIZED; } diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index 2413a78f0e..505ae11760 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp @@ -40,7 +40,6 @@ namespace { class EmulationSession final { public: EmulationSession() { - m_system.Initialize(); m_vfs = std::make_shared(); } @@ -126,7 +125,6 @@ public: // Initialize system. m_system.SetShuttingDown(false); - m_system.Initialize(); m_system.ApplySettings(); m_system.HIDCore().ReloadInputDevices(); m_system.SetContentProvider(std::make_unique()); @@ -498,9 +496,12 @@ jstring Java_org_yuzu_yuzu_1emu_NativeLibrary_GetGitRevision([[maybe_unused]] JN return {}; } -void Java_org_yuzu_yuzu_1emu_NativeLibrary_CreateConfigFile +void Java_org_yuzu_yuzu_1emu_NativeLibrary_InitializeEmulation [[maybe_unused]] (JNIEnv* env, [[maybe_unused]] jclass clazz) { + // Create the default config.ini. Config{}; + // Initialize the emulated system. + EmulationSession::GetInstance().System().Initialize(); } jint Java_org_yuzu_yuzu_1emu_NativeLibrary_DefaultCPUCore([[maybe_unused]] JNIEnv* env, diff --git a/src/android/app/src/main/jni/native.h b/src/android/app/src/main/jni/native.h index f799560e47..192c9261d3 100644 --- a/src/android/app/src/main/jni/native.h +++ b/src/android/app/src/main/jni/native.h @@ -86,8 +86,8 @@ JNIEXPORT void JNICALL Java_org_yuzu_yuzu_1emu_NativeLibrary_SetSysDirectory(JNI jclass clazz, jstring path); -JNIEXPORT void JNICALL Java_org_yuzu_yuzu_1emu_NativeLibrary_CreateConfigFile(JNIEnv* env, - jclass clazz); +JNIEXPORT void JNICALL Java_org_yuzu_yuzu_1emu_NativeLibrary_InitializeEmulation(JNIEnv* env, + jclass clazz); JNIEXPORT jint JNICALL Java_org_yuzu_yuzu_1emu_NativeLibrary_DefaultCPUCore(JNIEnv* env, jclass clazz);