external/jnipp: Check and re-assign JNIEnv

Fixes a crash when resumed from launcher.

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2226>
This commit is contained in:
Hui Xu 2024-05-30 18:16:43 +08:00 committed by Marge Bot
parent 5b8edfbb30
commit cdb9c38ee0
2 changed files with 16 additions and 2 deletions

View file

@ -1 +1,4 @@
jnipp: Update to fix issues including CTS crashes.
---
- mr.2226
---
jnipp: Update/patch to fix issues, including crashes.

View file

@ -156,11 +156,22 @@ namespace jni
#endif // _WIN32
static bool isEnvChanged(JavaVM* vm, ScopedEnv& threadLocalEnv) {
if (vm == nullptr)
{
return false;
}
JNIEnv *curEnv = nullptr;
getEnv(vm, &curEnv);
return curEnv != threadLocalEnv.get();
}
JNIEnv* env()
{
static thread_local ScopedEnv env;
if (env.get() != nullptr && !isAttached(javaVm))
if (env.get() != nullptr && (!isAttached(javaVm) || isEnvChanged(javaVm, env)))
{
// we got detached, so clear it.
// will be re-populated from static javaVm below.