AttachCurrentThread与
崩溃# 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
从新创建的线程调用时。
为什么?
我用函数needJ调用它,从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在两个调用中都是相同的。该线程是使用从TThread派生的对象创建的,该对象从其execute方法调用needJ。
使用java 6/7和openjdk 7发生崩溃。但是,在Android上它可以正常运行。