diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-22 12:52:16 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-22 12:52:16 +0200 |
commit | 8c474ddd4999883749b987b2d4b4c70f00ebd94d (patch) | |
tree | c6602732cad5bf09c73b991b6ee8dc9548df924c /modules/openxr | |
parent | 4b6629978e8d1be15c5e3bc74db55900fa40f52e (diff) | |
parent | f291a4ed3a64dd95bf8136f352e5d0554ada4a7c (diff) | |
download | redot-engine-8c474ddd4999883749b987b2d4b4c70f00ebd94d.tar.gz |
Merge pull request #90710 from m4gr3d/fix_jstring_leaks
Fix leakage of JNI object references
Diffstat (limited to 'modules/openxr')
-rw-r--r-- | modules/openxr/extensions/platform/openxr_android_extension.cpp | 22 | ||||
-rw-r--r-- | modules/openxr/extensions/platform/openxr_android_extension.h | 4 |
2 files changed, 15 insertions, 11 deletions
diff --git a/modules/openxr/extensions/platform/openxr_android_extension.cpp b/modules/openxr/extensions/platform/openxr_android_extension.cpp index de542828c3..04404923ef 100644 --- a/modules/openxr/extensions/platform/openxr_android_extension.cpp +++ b/modules/openxr/extensions/platform/openxr_android_extension.cpp @@ -36,7 +36,6 @@ #include "os_android.h" #include "thread_jandroid.h" -#include <jni.h> #include <openxr/openxr.h> #include <openxr/openxr_platform.h> @@ -48,6 +47,12 @@ OpenXRAndroidExtension *OpenXRAndroidExtension::get_singleton() { OpenXRAndroidExtension::OpenXRAndroidExtension() { singleton = this; + + JNIEnv *env = get_jni_env(); + ERR_FAIL_NULL(env); + + env->GetJavaVM(&vm); + activity_object = env->NewGlobalRef(static_cast<OS_Android *>(OS::get_singleton())->get_godot_java()->get_activity()); } HashMap<String, bool *> OpenXRAndroidExtension::get_requested_extensions() { @@ -66,11 +71,6 @@ void OpenXRAndroidExtension::on_before_instance_created() { } loader_init_extension_available = true; - JNIEnv *env = get_jni_env(); - JavaVM *vm; - env->GetJavaVM(&vm); - jobject activity_object = env->NewGlobalRef(static_cast<OS_Android *>(OS::get_singleton())->get_godot_java()->get_activity()); - XrLoaderInitInfoAndroidKHR loader_init_info_android = { .type = XR_TYPE_LOADER_INIT_INFO_ANDROID_KHR, .next = nullptr, @@ -93,11 +93,6 @@ void *OpenXRAndroidExtension::set_instance_create_info_and_get_next_pointer(void return nullptr; } - JNIEnv *env = get_jni_env(); - JavaVM *vm; - env->GetJavaVM(&vm); - jobject activity_object = env->NewGlobalRef(static_cast<OS_Android *>(OS::get_singleton())->get_godot_java()->get_activity()); - instance_create_info = { .type = XR_TYPE_INSTANCE_CREATE_INFO_ANDROID_KHR, .next = p_next_pointer, @@ -109,4 +104,9 @@ void *OpenXRAndroidExtension::set_instance_create_info_and_get_next_pointer(void OpenXRAndroidExtension::~OpenXRAndroidExtension() { singleton = nullptr; + + JNIEnv *env = get_jni_env(); + ERR_FAIL_NULL(env); + + env->DeleteGlobalRef(activity_object); } diff --git a/modules/openxr/extensions/platform/openxr_android_extension.h b/modules/openxr/extensions/platform/openxr_android_extension.h index e51b5824e8..61f4b02ab6 100644 --- a/modules/openxr/extensions/platform/openxr_android_extension.h +++ b/modules/openxr/extensions/platform/openxr_android_extension.h @@ -34,6 +34,8 @@ #include "../../util.h" #include "../openxr_extension_wrapper.h" +#include <jni.h> + class OpenXRAndroidExtension : public OpenXRExtensionWrapper { public: static OpenXRAndroidExtension *get_singleton(); @@ -49,6 +51,8 @@ public: private: static OpenXRAndroidExtension *singleton; + JavaVM *vm; + jobject activity_object; bool loader_init_extension_available = false; bool create_instance_extension_available = false; |