Browse Source

* pas2jni: Fixed invoking of Java event handlers from non-main threads.

git-svn-id: trunk@34309 -
yury 9 years ago
parent
commit
3b8db21c2c
1 changed files with 4 additions and 0 deletions
  1. 4 0
      utils/pas2jni/writer.pas

+ 4 - 0
utils/pas2jni/writer.pas

@@ -1265,6 +1265,7 @@ begin
     Fps.WriteLn('var');
     Fps.IncI;
     Fps.WriteLn('_env: PJNIEnv;');
+    Fps.WriteLn('_new_env: boolean;');
     Fps.WriteLn('_mpi: _TMethodPtrInfo;');
     if d.Count > 0 then begin
       Fps.WriteLn(Format('_args: array[0..%d] of jvalue;', [d.Count - 1]));
@@ -1281,6 +1282,8 @@ begin
     Fps.WriteLn('begin');
     Fps.IncI;
     Fps.WriteLn('CurJavaVM^^.GetEnv(CurJavaVM, @_env, JNI_VERSION_1_6);');
+    Fps.WriteLn('_new_env:=_env = nil;');
+    Fps.WriteLn('if _new_env then CurJavaVM^^.AttachCurrentThread(CurJavaVM, @_env, nil);');
     Fps.WriteLn('_env^^.PushLocalFrame(_env, 100);');
     Fps.WriteLn('try');
     Fps.IncI;
@@ -1347,6 +1350,7 @@ begin
     Fps.DecI;
     Fps.WriteLn('finally');
     Fps.WriteLn('_env^^.PopLocalFrame(_env, nil);', 1);
+    Fps.WriteLn('if _new_env then CurJavaVM^^.DetachCurrentThread(CurJavaVM);', 1);
     Fps.WriteLn('end;');
     Fps.DecI;
     Fps.WriteLn('end;');