Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 40d4e55

Browse files
committed
[[ Bug 22996 ]] Fix JNI error calling methods that trigger callbacks
This patch fixes an issue where calling a java method results in engine callbacks that change the value of the `s_env` JNIEnv variable causing it to be incorrect for the current thread when the method returns. The fix restores the correct environment for the current thread.
1 parent 10e79b4 commit 40d4e55

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

docs/lcb/notes/22996.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [22996] Fix JNI error calling methods that trigger engine callbackss

libfoundation/src/foundation-java-private.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,11 @@ bool MCJavaPrivateCallJNIMethod(MCNameRef p_class_name, void *p_method_id, int p
17141714
default:
17151715
MCUnreachableReturn(false);
17161716
}
1717+
1718+
/* In the event the method called resulted in engine callbacks that may have
1719+
* altered s_env we need to ensure we are making calls on the correct
1720+
* environment */
1721+
MCJavaDoAttachCurrentThread();
17171722

17181723
// If we got here there were no memory errors. Check the JNI Env for
17191724
// exceptions

0 commit comments

Comments
 (0)