summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-07-05 10:04:16 +0200
committerSven Gothel <[email protected]>2023-07-05 10:04:16 +0200
commitae4c2c3e59ed92caa6f0e18360b7236e50899bf6 (patch)
tree4f19c0991b4dd54debb36a5c1c57f71bca848575 /src/java/com/jogamp/gluegen/JavaCallbackEmitter.java
parent0c4067379e5e12617b9a4530e607ca34762b54e3 (diff)
GlueGen JavaCallback/LibraryOnLoad: Always include the `libraryBasename` agnostic 'emitJNIEnvDecl()' (declaration) in JNI code; Detach the thread from the JVM if newly attach in callback!
Diffstat (limited to 'src/java/com/jogamp/gluegen/JavaCallbackEmitter.java')
-rw-r--r--src/java/com/jogamp/gluegen/JavaCallbackEmitter.java5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java b/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java
index 96e1e77..b152801 100644
--- a/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java
+++ b/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java
@@ -578,7 +578,8 @@ public final class JavaCallbackEmitter {
unit.emitln(") {");
// javaCallback.cbFuncCEmitter.emitBody();
{
- unit.emitln(" JNIEnv* env = JVMUtil_GetJNIEnv();");
+ unit.emitln(" int detachJVM = 0;");
+ unit.emitln(" JNIEnv* env = JVMUtil_GetJNIEnv(1 /* daemon */, &detachJVM);");
unit.emitln(" jclass cbClazz = "+staticBindingClazzVarName+";");
unit.emitln(" jmethodID cbMethod = "+staticBindingMethodIDVarName+";");
unit.emitln(" if( NULL == env || NULL == cbClazz || NULL == cbMethod ) {");
@@ -623,7 +624,7 @@ public final class JavaCallbackEmitter {
// javaCallback.cbFuncCEmitter.emitBodyUserVariableAssignments();
// javaCallback.cbFuncCEmitter.emitBodyVariablePostCallCleanup();
// javaCallback.cbFuncCEmitter.emitBodyMapCToJNIType(-1 /* return value */, true /* addLocalVar */)
-
+ unit.emitln(" JVMUtil_ReleaseJNIEnv(env, detachJVM);");
unit.emitln(" "+returnStatement);
}
unit.emitln("}");