Recent

Author Topic: System crash with ShowMessage  (Read 2882 times)

MaxCuriosus

  • Full Member
  • ***
  • Posts: 136
System crash with ShowMessage
« on: April 29, 2020, 01:27:38 am »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 11164
  • Debugger - SynEdit - and more
    • wiki
Re: System crash with ShowMessage
« Reply #1 on: April 29, 2020, 01:41:14 am »
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

  • Full Member
  • ***
  • Posts: 136
Re: System crash with ShowMessage
« Reply #2 on: April 29, 2020, 05:00:55 pm »
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

  • Hero Member
  • *****
  • Posts: 3197
Re: System crash with ShowMessage
« Reply #3 on: April 29, 2020, 06:01:34 pm »
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

« Last Edit: April 29, 2020, 06:03:10 pm by winni »

Thaddy

  • Hero Member
  • *****
  • Posts: 16945
  • Ceterum censeo Trump esse delendam
Re: System crash with ShowMessage
« Reply #4 on: April 29, 2020, 06:32:26 pm »
Show us some code...
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: System crash with ShowMessage
« Reply #5 on: April 29, 2020, 06:39:15 pm »
Hi!

This testcode reached just the upper limit 10 000 000 bytes with no problems:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var s : ShortString;
  3.     i : integer;
  4. begin
  5. setLength(s,60);
  6. s[60] := ' ';
  7. while length (Memo1.Text) <10000000 do
  8.    begin
  9.    for i := 1 to 59 do s[i] := chr(Random(96)+32);
  10.    memo1.lines.add(s);
  11.    Label1.Caption := IntToStr(Length(Memo1.Text));
  12.    application.ProcessMessages;
  13.    end;
  14. end;                                                      
  15.  

With the application.ProcessMessages that takes some time.

Winni

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: System crash with ShowMessage
« Reply #6 on: April 29, 2020, 07:08:17 pm »
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.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11164
  • Debugger - SynEdit - and more
    • wiki
Re: System crash with ShowMessage
« Reply #7 on: April 29, 2020, 08:01:06 pm »
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.
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

  • Hero Member
  • *****
  • Posts: 3197
Re: System crash with ShowMessage
« Reply #8 on: April 29, 2020, 08:39:31 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
« Last Edit: April 29, 2020, 08:43:59 pm by winni »

MaxCuriosus

  • Full Member
  • ***
  • Posts: 136
Re: System crash with ShowMessage
« Reply #9 on: April 30, 2020, 12:42:01 am »
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.

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][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. const
  3.   S='012345678901234567890123456789012'; { 33 characters }
  4.   NbLines=1600; { OK at 1600, crash at 2000 }
  5. Var
  6.   SL: TStringList;
  7.   I,TotBytes: Integer;
  8. begin
  9.   SL:=TStringList.Create;
  10.   TotBytes:=0;
  11.   For I:=1 to NbLines do
  12.    Begin
  13.      SL.Add(S);
  14.      TotBytes:=TotBytes+Length(S)+1;
  15.    end;
  16.   ShowMessage('TotalBytes='+IntToStr(TotBytes));
  17.   ShowMessage(SL.Text);
  18. //  Memo1.Text:=SL.Text;
  19.   SL.Free;
  20. end;

jamie

  • Hero Member
  • *****
  • Posts: 6892
Re: System crash with ShowMessage
« Reply #10 on: April 30, 2020, 01:14:08 am »
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.

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][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. const
  3.   S='012345678901234567890123456789012'; { 33 characters }
  4.   NbLines=1600; { OK at 1600, crash at 2000 }
  5. Var
  6.   SL: TStringList;
  7.   I,TotBytes: Integer;
  8. begin
  9.   SL:=TStringList.Create;
  10.   TotBytes:=0;
  11.   For I:=1 to NbLines do
  12.    Begin
  13.      SL.Add(S);
  14.      TotBytes:=TotBytes+Length(S)+1;
  15.    end;
  16.   ShowMessage('TotalBytes='+IntToStr(TotBytes));
  17.   ShowMessage(SL.Text);
  18. //  Memo1.Text:=SL.Text;
  19.   SL.Free;
  20. end;

I would wager it would survive up to around ~1870
The only true wisdom is knowing you know nothing

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: System crash with ShowMessage
« Reply #11 on: April 30, 2020, 01:28:27 am »
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][+][-]
  1.  procedure TForm1.Button2Click(Sender: TObject);
  2.     const
  3.       S='012345678901234567890123456789012'; { 33 characters }
  4.       NbLines=10000; { No crash }
  5.     Var
  6.       SL: TStringList;
  7.       I: Integer;
  8.     begin
  9.       SL:=TStringList.Create;
  10.       For I:=1 to NbLines do
  11.        Begin
  12.          SL.Add(S);
  13.        end;
  14.       sl.Insert(0,IntToStr(Length(sl.Text)) );
  15.       ShowMessage(SL.Text);
  16.       SL.Free;
  17.     end;                  


Winni

MaxCuriosus

  • Full Member
  • ***
  • Posts: 136
Re: System crash with ShowMessage
« Reply #12 on: April 30, 2020, 09:58:51 pm »
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

  • Hero Member
  • *****
  • Posts: 3197
Re: System crash with ShowMessage
« Reply #13 on: April 30, 2020, 10:47:58 pm »
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

  • Full Member
  • ***
  • Posts: 136
Re: System crash with ShowMessage
« Reply #14 on: May 02, 2020, 02:38:14 pm »
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?

 

TinyPortal © 2005-2018