AttachCurrentThread crashes with
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f810fba15f5, pid=21079, tid=140192045909760
#
# JRE version: Java(TM) SE Runtime Environment (7.0_45-b18) (build 1.7.0_45-b18)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.45-b08 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V [libjvm.so+0x6305f5] attach_current_thread+0x1c5
when called from a newly created thread.
Why?
I call it with a function needJ, which works fine when called from the mainthread:
TJavaEnv = record
env: PJNIEnv;
//...
end;
threadvar j: TJavaEnv;
function needJ: TJavaEnv;
var attachArgs: JavaVMAttachArgs;
begin
if j.env = nil then begin
attachArgs.version:=JNI_VERSION_1_2;
attachArgs.name:=nil;
attachArgs.group:=nil;
if jvmref^^.AttachCurrentThread(jvmref,@j.env,@attachArgs) <> 0 then
raise EAndroidInterfaceException.create('Failed to get VM environment');
end;
result := j;
end;
jvmref is the same in both calls. The thread is created with an object derived from TThread, which calls needJ from its execute method.
The crashs occurs with java 6/7 and openjdk 7. However, on Android it works.