Forum > General
[SOLVED] CreateThread + String/Dynamic array inside thread proc = SIGSEGV crash
Syndrome:
Create new project, double click your form1 and paste this code:
--- Code: ---function SilentCrash( dummy:pointer ):dword; stdcall;
var
s:string;
begin
while true do begin
s:= 'asd';
sleep(10000);
end;
end;
procedure TForm1.FormCreate(Sender:TObject);
var
asd:dword;
begin
CreateThread( nil, 0, @SilentCrash, nil, 0, asd);
end;
--- End code ---
silent crash example 2:
--- Code: ---function SilentCrash( dummy:pointer ):dword; stdcall;
var
d:array of byte;
begin
while true do begin
setlength(d,10);
d[3]:= 2;
sleep(10000);
end;
end;
procedure TForm1.FormCreate(Sender:TObject);
var
asd:dword;
begin
CreateThread( nil, 0, @SilentCrash, nil, 0, asd);
end;
--- End code ---
Can anyone check this code?
Dont forget to include windows unit.
i cant use ansistrings and dynamic arrays outside main thread due to instant crashes.
if someone can compile examples above under win 8.1 x64 please answer this thread.
sorry for my awful english
my specs: win 8.1 x64 / lazarus 1.2.6 x32 / A10-4600M
engkin:
I think you need to use stdcall for calling convention.
Syndrome:
stdcall didnt help. I still cant compile this code. Application silently crashes before form1 is displayed
BrunoK:
Try moving it to TForm.OnShow like :
--- Code: --- TForm1 = class(TForm)
.
.
private
FShownOnce:boolean;
end;
.
.
procedure TForm1.FormShow(Sender: TObject);
var
asd: dword;
begin
if not FShownOnce then begin
FShownOnce:=True;
CreateThread(nil, 0, @SilentCrash, nil, 0, asd);
end;
end;
--- End code ---
Ocye:
cthreads included on Linux/MacOS? Otherwise try BeginThread() instead of CreateThread().
Navigation
[0] Message Index
[#] Next page