Hello.
When using PeekMessage under Linux(GTK2), the program occasionally crashes and exits.
Try-Except does not solve the problem(SIGABRT).
Code:
procedure TForm1.Button2Click(Sender: TObject);
begin
while true do
PMessages;
end;
procedure PMessages;
var
Msg: TMsg;
begin
while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do begin
if Msg.Message = WM_QUIT then exit;
{$IFNDEF Linux} //TODO?
TranslateMessage(Msg);
DispatchMessage(Msg);
{$ENDIF}
end;
Sleep(1);
end;
On average, an error occurs one minute after launch, but sometimes the program runs without errors for about half an hour.
If you do PeekMessage in a Thread, the error occurs a little faster (regardless of critical sections).function TGtk2WidgetSet.PeekMessage(var lpMsg: TMsg; Handle : HWND;
wMsgFilterMin, wMsgFilterMax, wRemoveMsg: UINT): Boolean;
var
vlItem : TGtkMessageQueueItem;
begin
//TODO Filtering
DebugLn('Peek !!!' );
fMessageQueue.Lock; //!!!!!!!!Error is here
try
vlItem := fMessageQueue.FirstMessageItem;
Result := vlItem <> nil;
if Result then begin
lpMsg := vlItem.Msg^;
if (wRemoveMsg and PM_REMOVE) = PM_REMOVE then
fMessageQueue.RemoveMessage(vlItem,FPMF_Internal,true);
end;
finally
fMessageQueue.UnLock;
end;
end;
procedure TGtkMessageQueue.Lock;
begin
if InterlockedIncrement(fLock)=1 then
{$IFDEF USE_GTK_MAIN_OLD_ITERATION}
EnterCriticalsection(FCritSec);
{$ELSE}
g_main_context_acquire(FMainContext); //then the path goes to the libraries. The error is here.
{$ENDIF}
end;
What can you advise or when will this error be fixed?
*
Checked for Lazarus 2.0.8, 2.0.10.
On different graphical shells(just in case).