diff --git a/app/src/main/cpp/emu_jni.cpp b/app/src/main/cpp/emu_jni.cpp index 0b040692..0df3d657 100644 --- a/app/src/main/cpp/emu_jni.cpp +++ b/app/src/main/cpp/emu_jni.cpp @@ -27,7 +27,7 @@ std::weak_ptr OsWeak; std::weak_ptr GpuWeak; std::weak_ptr AudioWeak; std::weak_ptr InputWeak; -std::weak_ptr SettingsWeak; +std::weak_ptr SettingsWeak; // https://cs.android.com/android/platform/superproject/+/master:bionic/libc/tzcode/bionic.cpp;l=43;drc=master;bpv=1;bpt=1 static std::string GetTimeZoneName() { @@ -85,7 +85,8 @@ extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_executeApplication( auto jvmManager{std::make_shared(env, instance)}; - std::shared_ptr settings{std::make_shared(env, settingsInstance)}; + auto androidSettings{std::make_shared(env, settingsInstance)}; + std::shared_ptr settings{androidSettings}; skyline::JniString publicAppFilesPath(env, publicAppFilesPathJstring); skyline::Logger::EmulationContext.Initialize(publicAppFilesPath + "logs/emulation.sklog"); @@ -115,7 +116,7 @@ extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_executeApplication( GpuWeak = os->state.gpu; AudioWeak = os->state.audio; InputWeak = os->state.input; - SettingsWeak = settings; + SettingsWeak = androidSettings; jvmManager->InitializeControllers(); skyline::Logger::DebugNoPrefix("Launching ROM {}", skyline::JniString(env, romUriJstring)); @@ -247,6 +248,7 @@ extern "C" JNIEXPORT void JNICALL Java_emu_skyline_utils_NativeSettings_updateNa auto settings{SettingsWeak.lock()}; if (!settings) return; // We don't mind if we miss settings updates while settings haven't been initialized + settings->BeginTransaction(env); settings->Update(); } diff --git a/app/src/main/cpp/skyline/common/android_settings.h b/app/src/main/cpp/skyline/common/android_settings.h index ec7318ec..45ce49d7 100644 --- a/app/src/main/cpp/skyline/common/android_settings.h +++ b/app/src/main/cpp/skyline/common/android_settings.h @@ -20,14 +20,12 @@ namespace skyline { * @note Will construct the underlying KtSettings object in-place */ AndroidSettings(JNIEnv *env, jobject settingsInstance) : ktSettings(env, settingsInstance) { + ktSettings.BeginTransaction(env); Update(); } - /** - * @note Will take ownership of the passed KtSettings object - */ - AndroidSettings(KtSettings &&ktSettings) : ktSettings(std::move(ktSettings)) { - Update(); + void BeginTransaction(JNIEnv *env) { + ktSettings.BeginTransaction(env); } void Update() override { @@ -50,6 +48,6 @@ namespace skyline { disableSubgroupShuffle = ktSettings.GetBool("disableSubgroupShuffle"); isAudioOutputDisabled = ktSettings.GetBool("isAudioOutputDisabled"); validationLayer = ktSettings.GetBool("validationLayer"); - }; + } }; } diff --git a/app/src/main/cpp/skyline/gpu/presentation_engine.cpp b/app/src/main/cpp/skyline/gpu/presentation_engine.cpp index 8f610583..196f4075 100644 --- a/app/src/main/cpp/skyline/gpu/presentation_engine.cpp +++ b/app/src/main/cpp/skyline/gpu/presentation_engine.cpp @@ -33,7 +33,7 @@ namespace skyline::gpu { auto desc{presentationTrack.Serialize()}; desc.set_name("Presentation"); perfetto::TrackEvent::SetTrackDescriptor(presentationTrack, desc); - state.settings->disableFrameThrottling.AddCallback(std::bind(&PresentationEngine::OnDisableFrameThrottlingChanged, this, std::placeholders::_1)); + state.settings->disableFrameThrottling.AddCallback([this](auto && value) { OnDisableFrameThrottlingChanged(value); }); } PresentationEngine::~PresentationEngine() { diff --git a/app/src/main/cpp/skyline/jvm.h b/app/src/main/cpp/skyline/jvm.h index 535a307a..30f5cabf 100644 --- a/app/src/main/cpp/skyline/jvm.h +++ b/app/src/main/cpp/skyline/jvm.h @@ -25,12 +25,12 @@ namespace skyline { */ class KtSettings { private: - JNIEnv *env; //!< A pointer to the current jni environment + JNIEnv *env{}; //!< The JNI environment jclass settingsClass; //!< The settings class jobject settingsInstance; //!< The settings instance public: - KtSettings(JNIEnv *env, jobject settingsInstance) : env(env), settingsInstance(settingsInstance), settingsClass(env->GetObjectClass(settingsInstance)) {} + KtSettings(JNIEnv *env, jobject settingsInstance) : settingsInstance(env->NewGlobalRef(settingsInstance)), settingsClass(reinterpret_cast(env->NewGlobalRef(env->GetObjectClass(settingsInstance)))) {} KtSettings(const KtSettings &) = delete; @@ -38,6 +38,10 @@ namespace skyline { KtSettings(KtSettings &&) = default; + void BeginTransaction(JNIEnv *pEnv) { + this->env = pEnv; + } + /** * @param key A null terminated string containing the key of the setting to get */