Lazarus

Programming => Packages and Libraries => RichMemo => Topic started by: guest60499 on February 08, 2017, 05:07:06 pm

Title: [SOLVED] Update of TRichMemo from TThread crashes GTK2.
Post by: guest60499 on February 08, 2017, 05:07:06 pm
The lines are properly added, per:
Code: Pascal  [Select]
  1. procedure TTCPClient.Execute;
  2. var
  3.   Line: String;
  4. begin
  5.   try
  6.     Socket.SSL.CertCAFile := FCertFile;
  7.     Socket.Connect(FHost, IntToStr(FPort));
  8.     Socket.SSLDoConnect;
  9.  
  10.     if Socket.LastError <> 0 then
  11.     begin
  12.       if FOnError <> nil then
  13.         FOnError(Self, Socket.LastError, Socket.LastErrorDesc);
  14.       Exit;
  15.     end
  16.     else
  17.     begin
  18.       if FOnConnect <> nil then
  19.         FOnConnect(Self);
  20.       FConnected := True;
  21.     end;
  22.  
  23.     repeat
  24.       while Socket.CanRead(1000) do
  25.       begin
  26.         Line := Socket.RecvString(1);
  27.         if Line = '' then
  28.            continue;
  29.  
  30.         Window.LogClient(Line);
  31.       end;
  32.     until False;
  33.   finally
  34.     if FOnDisconnect <> nil then
  35.       FOnDisconnect(Self);
  36.     Socket.Free;
  37.   end;
  38. end;

Where Window is a TConnectionWindow and LogClient appends to a TRichMemo's Text and sets some styling attributes. After some time the following happens:
Code: [Select]
(relgui:17611): Gtk-CRITICAL **: gtk_text_layout_real_invalidate: assertion 'layout->wrap_loop_count == 0' failed

(relgui:17611): Gtk-CRITICAL **: gtk_text_layout_real_invalidate: assertion 'layout->wrap_loop_count == 0' failed

(relgui:17611): Gtk-CRITICAL **: gtk_text_layout_real_invalidate: assertion 'layout->wrap_loop_count == 0' failed

(relgui:17611): Gtk-CRITICAL **: gtk_text_layout_real_invalidate: assertion 'layout->wrap_loop_count == 0' failed
**
Gdk:ERROR:/home/jmm/scratch/gtk/gtk+2.0-2.24.25/gdk/gdkregion-generic.c:1110:miUnionNonO: assertion failed: (y1 < y2)
Aborted

Is it necessary to use critical sections to access the GUI elements? There should be no contention issues. I am starting to feel I may need to restructure the project completely (e.g. message queues) due to limitations of GTK.
Title: Re: Update of TRichMemo from TThread crashes GTK2.
Post by: Bart on February 08, 2017, 05:11:46 pm
You should not update GUI from mainthread in a separate thread.
Use synchronize method.

Bart
Title: Re: Update of TRichMemo from TThread crashes GTK2.
Post by: guest60499 on February 08, 2017, 06:15:29 pm
You should not update GUI from mainthread in a separate thread.
Use synchronize method.

Bart

Yep, Synchronize updates the UI properly. It's maddening that it works some of the time. Luckily Synchronize lets me keep certain data within the TThread descendant, because otherwise it devolves into a mess of message passing.