System crash with ShowMessage lazarus / 31-LCL ---------------------------------------------------------------------- MaxCuriosus · 2020-04-28 23:27 After adding about 7000 short strings to a TStringList variable, say SL, I've tried to view them with a ShowMessage(SL.Text) but the system crashes. Is this to be expected because of the large amount of strings or is it a bug? Deb9 / Laz2.0.2 / FPC3.0.4 / gtk2 ---------------------------------------------------------------------- Martin_fr · 2020-04-28 23:41 Good question. Could be any number of things. Not sure how much gtk is involved. Or how it deals with what I guess is a rather long string for a message dlg. You could try to add a memo, and do memo.text := sl.text ---------------------------------------------------------------------- MaxCuriosus · 2020-04-29 15:00 After a few simple tests I've observed that the threshold for crashing is around 52k for both the ShowMessage and Memo. Note that's not a hard crash requiring a reboot but rather a soft one that allows me to regain control after a few odd graphics things and perhaps via a user login form. Memo seems to be a little more friendlier in that respect. ---------------------------------------------------------------------- winni · 2020-04-29 16:01 Hi! Strange, strange! I am just running a test. Adding a stortstring with the length of 60 in an infinite loop to a Memo. And let a Label show the length of the Memo.text. In the moment the test reached just 6 MB and is still running. My system is Lin64, Suse Tumbleweed, Lazarus 2.08, fpc 3.04, 64 Bit Winni PS.: Just 6.3 MB ---------------------------------------------------------------------- Thaddy · 2020-04-29 16:32 Show us some code... ---------------------------------------------------------------------- winni · 2020-04-29 16:39 Hi! This testcode reached just the upper limit 10 000 000 bytes with no problems: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var s : ShortString;    i : integer;beginsetLength(s,60);s[60] := ' ';while length (Memo1.Text) <10000000 do   begin   for i := 1 to 59 do s[i] := chr(Random(96)+32);   memo1.lines.add(s);   Label1.Caption := IntToStr(Length(Memo1.Text));   application.ProcessMessages;   end;end;                                                     With the application.ProcessMessages that takes some time. Winni ---------------------------------------------------------------------- lucamar · 2020-04-29 17:08 A memo shouldn't give any problem with a meagre 7K lines. ShowMessage, though, is meant to show a relatively short text and not only is it quite limited but depends heavily on the facilities of the window or composition manager. In this machine, for example, a 64KiB message is about the limit, and the window occupies almost the whole screen; a few more lines and not only crashes the application, but also Metacity (the composition/theme manager) itself. It might be due to a buffer overflow, overflows when calculating the size and/or position of the messsage window, or a miriad other things, but the underlying reason is that the widget isn't meant for that. If you really need to show such a big message you'd better write your own message dialog using controls (like TMemo) able to handle such quantities of text. ---------------------------------------------------------------------- Martin_fr · 2020-04-29 18:01 Quote from: MaxCuriosus on April 29, 2020, 05:00:55 pmAfter a few simple tests I've observed that the threshold for crashing is around 52k for both the ShowMessage and Memo. Note that's not a hard crash requiring a reboot but rather a soft one that allows me to regain control after a few odd graphics things and perhaps via a user login form. Memo seems to be a little more friendlier in that respect. If it crashes a with memo at 52k, then there is a bug somewhere. And, Stringlist and memo have been around a long time. So I would think it highly likely that the bug is in your code. Or maybe you have special chars (like #0) in your text. Not sure what a memo will do with that (under gtk2). Or bad UTF-8? ---------------------------------------------------------------------- winni · 2020-04-29 18:39 Quote from: Martin_fr on April 29, 2020, 08:01:06 pm Or maybe you have special chars (like #0) in your text. Not sure what a memo will do with that (under gtk2). Or bad UTF-8? No - very stable! If you assign values from random (256) to every char the Memo behaves very kind: * Due to the illegal values it slows down horrible * Every value  <32  and >127 is shown through the utf8 substitute sign with the 4 hex values Awful slow! Now at byte ~ 20 000 Talking about gtk2 Winni ---------------------------------------------------------------------- MaxCuriosus · 2020-04-29 22:42 Quote from: Martin_fr on April 29, 2020, 08:01:06 pmIf it crashes a with memo at 52k, then there is a bug somewhere. And, Stringlist and memo have been around a long time. So I would think it highly likely that the bug is in your code. I will probably agree, but the "Memo" code has since been removed from the project where it was embedded, so I can't point to what was my probable mistake. On the other hand in a stand-alone test the "ShowMessage" consistently fails from around 52k, and the "Memo" works properly and fast. See code below. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);const  S='012345678901234567890123456789012'; { 33 characters }  NbLines=1600; { OK at 1600, crash at 2000 }Var  SL: TStringList;  I,TotBytes: Integer;begin  SL:=TStringList.Create;  TotBytes:=0;  For I:=1 to NbLines do   Begin     SL.Add(S);     TotBytes:=TotBytes+Length(S)+1;   end;  ShowMessage('TotalBytes='+IntToStr(TotBytes));  ShowMessage(SL.Text);//  Memo1.Text:=SL.Text;  SL.Free;end; ---------------------------------------------------------------------- jamie · 2020-04-29 23:14 Quote from: MaxCuriosus on April 30, 2020, 12:42:01 amQuote from: Martin_fr on April 29, 2020, 08:01:06 pmIf it crashes a with memo at 52k, then there is a bug somewhere. And, Stringlist and memo have been around a long time. So I would think it highly likely that the bug is in your code. I will probably agree, but the "Memo" code has since been removed from the project where it was embedded, so I can't point to what was my probable mistake. On the other hand in a stand-alone test the "ShowMessage" consistently fails from around 52k, and the "Memo" works properly and fast. See code below. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);const  S='012345678901234567890123456789012'; { 33 characters }  NbLines=1600; { OK at 1600, crash at 2000 }Var  SL: TStringList;  I,TotBytes: Integer;begin  SL:=TStringList.Create;  TotBytes:=0;  For I:=1 to NbLines do   Begin     SL.Add(S);     TotBytes:=TotBytes+Length(S)+1;   end;  ShowMessage('TotalBytes='+IntToStr(TotBytes));  ShowMessage(SL.Text);//  Memo1.Text:=SL.Text;  SL.Free;end; I would wager it would survive up to around ~1870 ---------------------------------------------------------------------- winni · 2020-04-29 23:28 Hi! What are you doing? I have set NbLines to 10 000 and there is no crash. This results in 340 000 bytes The only problem is, that you need an OK button on top - and not at bottom. So the bug must be elsewhere. Made a slightly shortened code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  procedure TForm1.Button2Click(Sender: TObject);    const      S='012345678901234567890123456789012'; { 33 characters }      NbLines=10000; { No crash }    Var      SL: TStringList;      I: Integer;    begin      SL:=TStringList.Create;      For I:=1 to NbLines do       Begin         SL.Add(S);       end;      sl.Insert(0,IntToStr(Length(sl.Text)) );      ShowMessage(SL.Text);    SL.Free;    end;                   Winni ---------------------------------------------------------------------- MaxCuriosus · 2020-04-30 19:58 I have attached the complete stand-alone test progam. With "Deb9/Laz2.0.2/FPC3.0.4/gtk2" configuration the crash occurs consistently from about 56,100 bytes, 1650 lines in the test program. With "Win8/Laz1.8.0/FPC3.0.4" configuration the same program behaves properly with much more bytes, 3,500,000 bytes (100,000 lines) for exemple. So I reiterate my original question, is this a bug in Lazarus/Pascal? ---------------------------------------------------------------------- winni · 2020-04-30 20:47 Hi! I Just tested your code with Laz 2.08/fpc3.04 64 Bit on Linux Suse Tumbleweed. No problems, even if I set Nblines to 20 000. ShowMessage and the stringlist exist since the very early days of Lazarus. So it is not probable that there is a bug . You never told us with which message the system crashes. So it is hard to say what the reason is: Bad Lazarus/ fpc installation? Bad gtk installation? Some Debian problems? Or even hardware problems? Winni ---------------------------------------------------------------------- MaxCuriosus · 2020-05-02 12:38 Further tests. 1) With the same code as attached in Reply #12, the executable will also crash on a different computer with Deb9 Live, Deb10 Live or Tails4.5, however with different thresholds. 2) After the upgrade from Laz2.0.2 to Laz2.0.6 the same crashes occur. 3) If the executable is not run directly but with the debugger (F9), the debugger console shows a series of messages and the system hangs for a while. After regaining control I was able to take a screenshot of the debugger console (see attachment). Can somebody help me analyse these messages? ---------------------------------------------------------------------- lucamar · 2020-05-02 14:09 Quote from: MaxCuriosus on May 02, 2020, 02:38:14 pmCan somebody help me analyse these messages? Running from the terminal in this machine says something similar:Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i (project1:7625): Gdk-WARNING **: Native Windows wider or taller than 65535 pixels are not supported It means basically what it says: someone tried to create a too large window. Most probably the window or composition manager calculates how big the window must be to accomodate all the text without regard to size limits and blithely tries to create and use such a window which, since it fails at the low-level, makes the application/wm/cm crash down. What it sounds like is as if the middle (WM/CM) or high (LCL) level layers weren't checking whether the base "toolkit" (Gtk in this case) returns a valid window or errors out. Strange, but it can happen ... ---------------------------------------------------------------------- winni · 2020-05-02 16:31 Hi! As MaxCuriosus uses the same Lazurus and fpc version like me, I think the error is in a deeper level. And gtk does not talk about it's own error but received an error from the X Window System, that a native Window can't be bigger than 32767 x 32767. The program did not crash with Windows and and up to date KDE. So there are three possibilities : * The X 11 system is outdated or * The desktop system including the window manager is outdated. * Or both. With which desktop did you ran the tests? Winni ---------------------------------------------------------------------- lucamar · 2020-05-02 16:46 Quote from: winni on May 02, 2020, 06:31:35 pmWith which desktop did you ran the tests? Ubuntu 12.04 and Ubuntu 18.04 (Gnome session, not Unity). The quoted message is from the (much) older Ubuntu (which for the moment is my "main" OS) but the more recent failed the same way.