File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -518,6 +518,10 @@ void setup_android_class_loader() {
518518 // This ClassLoader will be used by jni_find_class() to locate classes at runtime
519519 // in a thread-safe manner, avoiding issues with FindClass in non-main threads.
520520
521+ if (android_class_loader) {
522+ cleanup_android_class_loader ();
523+ }
524+
521525 JNIEnv *env = get_jni_env ();
522526 ERR_FAIL_NULL (env);
523527
@@ -553,12 +557,23 @@ void cleanup_android_class_loader() {
553557 JNIEnv *env = get_jni_env ();
554558 if (env) {
555559 env->DeleteGlobalRef (android_class_loader);
556- android_class_loader = nullptr ;
560+ } else {
561+ ERR_PRINT (" Failed to release Android ClassLoader - JNIEnv is not available." );
557562 }
563+ android_class_loader = nullptr ;
564+ load_class_method = nullptr ;
558565 }
559566}
560567
561568jclass jni_find_class (JNIEnv *p_env, const char *p_class_name) {
569+ ERR_FAIL_NULL_V (p_env, nullptr );
570+ ERR_FAIL_NULL_V (p_class_name, nullptr );
571+
572+ if (!android_class_loader || !load_class_method) {
573+ ERR_PRINT (" Android ClassLoader is not initialized. Falling back to FindClass." );
574+ return p_env->FindClass (p_class_name);
575+ }
576+
562577 jstring java_class_name = p_env->NewStringUTF (p_class_name);
563578 jobject class_object = p_env->CallObjectMethod (
564579 android_class_loader,
You can’t perform that action at this time.
0 commit comments