Under android, why does TThread.synchronize follow CallInUIThread result when application crashes?
I have a very simple code below that runs under Android:
type
TmyObject = class(Tobject)
public
fint: integer;
destructor Destroy; override;
end;
destructor TmyObject.Destroy;
begin
TThread.synchronize(nil,
procedure
begin
fint := 26;
end);
CallInUIThread(
procedure
begin
end);
inherited;
end;
procedure TForm1.Button1Click(Sender: TObject);
var aObject: TmyObject;
begin
aObject := TmyObject.Create;
aObject.free;
end;
And I don't understand why it crashes on a class segmentation fault when we click on Button1Click?
What I know:
- IF I only delete
TThread.synchronize
it is not a glitch - IF I only delete
CallInUIThread
it is not a glitch - If removed
fint := 26;
it is not a glitch - IF I call
TThread.synchronize
+CallInUIThread
outside the destructor it doesn't crash
The procedure below fails (on CallInUIThread terminates)
function _InstClear(var Dest: TObject): Pointer;
{$IFDEF PUREPASCAL}
var
P: Pointer;
begin
Result := @Dest;
if Dest <> nil then
begin
P := Pointer(Dest);
Pointer(Dest) := nil;
TObject(P).__ObjRelease;
end;
end;
exactly inside
destructor TJavaLocal.Destroy;
begin
TJNIResolver.DeleteGlobalRef(FObjectID);
inherited;
end; <== here
below the stack trace:
System._InstClear(@0xa042672c: nil)
System._FinalizeArray(0xa042672c,0xa33c1af8,1)
System._FinalizeRecord(0xa0426720,0xa33c1c80)
System.TObject.CleanupInstance(0xa0426720)
System.TObject.FreeInstance(0xa0426720)
System._ClassDestroy(0xa0426720)
System.TObject.~TObject(0xa0426720,true)
System.TObject.__ObjRelease(0xa0426720)
System.TInterfacedObject._Release(0xa0426720)
:A231CC0E __stub_in16s__ZN6System17TInterfacedObject8_ReleaseEv24
System._IntfClear(@0xa0676cbc: nil)
System._FinalizeArray(0xa0676cbc,0xa313e480,1)
System._FinalizeRecord(0xa0676c98,0xa313e55c)
System.TObject.CleanupInstance(0xa0676c98)
System.TObject.FreeInstance(0xa0676c98)
System._ClassDestroy(0xa0676c98)
Androidapi.Jnibridge.TJavaLocal.~TJavaLocal(0xa0676c98,true)
System.TObject.__ObjRelease(0xa0676c98)
System._InstClear(@0xbe9c1b50: nil)
Androidapi.Jnibridge.dispatchToNative(0xb4857c00,0xbe9c1b9c,0xbe9c1ba0,0xbe9c1ba4,2691132568)
:A3A033EC ??
:A3A033EC ??
So let me assume this is an ARC problem, but I can't figure out what I did wrong? I'm under delphi Berlin
Note
I'm starting to be 99% sure it's an ARC bug
to do it without fail:
type
TmyObject = class(Tobject)
public
fint: integer;
destructor Destroy; override;
procedure AnProcedure;
end;
procedure TmyObject.AnProcedure;
begin
end;
destructor TmyObject.Destroy;
begin
TThread.synchronize(nil,
procedure
begin
fint := 26;
end);
CallInUIThread(AnProcedure);
inherited;
end;
procedure TForm1.Button1Click(Sender: TObject);
var aObject: TmyObject;
begin
aObject := TmyObject.Create;
aObject.free;
end;
so maybe in this procedure try to find a strong self-object reference and then destroy it at the end, but at the end the object is already destroyed because it is in the process of being destroyed.
+3
source to share
No one has answered this question yet
Check out similar questions: