Lazarus

Programming => Packages and Libraries => LazReport => Topic started by: sydenis on July 18, 2021, 05:39:43 pm

Title: Lazreport kills the application unpredictably
Post by: sydenis on July 18, 2021, 05:39:43 pm
I encountered incomprehensible behavior of Lazreport in different projects.
Usually do like this - I put the frReport1 component on the Datamodule (or on the form) and write the procedure:
Code: Pascal  [Select][+][-]
  1. procedure TdmReport.Print;
  2. begin
  3. frReport1.LoadFromFile('/data/test1.lrf');
  4. frReport1.ShowReport;
  5. end;

In some projects, this call passes without problems. But in other projects, the application crashes when ShowReport is called.
In this case, the following happens:
- No error messages are generated. The app just silently dies.
- The launch under the debbuger passes without errors. The required report opens without problems.

In my last big application, I put frReport1 on one of the forms and tried to call
Code: Pascal  [Select][+][-]
  1. frReport1.LoadFromFile('/data/test1.lrf');
  2. frReport1.ShowReport;
And I got a silent crash of the application.

I did the following experiment:

1. Created a clean project with a main form and a Datamodule with frReport1 component. I have inserted the Print procedure into the Datamodule. And there is only one button on the main form that calls Print.
I launch the application, press the button on the main form - and everything works fine. The report opens.

2. I connect the same Datamodule to my old application through the Project Inspector. In one of the forms, I call Print from the Datamodule and at the time of calling ShowReport, I get an application crash with familiar symptoms:
- No error messages are generated.
- The launch under the debager passes without errors.
I have little experience with Lazreport and I can't understand why in some cases the report opens, and in others the entire application crashes.
Please tell me what I'm doing wrong?

Ubuntu 20.04 + Lazarus 2.0.12
Title: Re: Lazreport kills the application unpredictably
Post by: dseligo on July 18, 2021, 07:14:04 pm
Try to catch error like this, maybe it will shed some light on the issue:

Code: Pascal  [Select][+][-]
  1. try
  2.   frReport1.LoadFromFile('/data/test1.lrf');
  3. except
  4.   on E: Exception do ShowMessage(E.Message);
  5. end;
  6.  
  7. try
  8.   frReport1.ShowReport;
  9. except
  10.   on E: Exception do ShowMessage(E.Message);
  11. end;
Title: Re: Lazreport kills the application unpredictably
Post by: sydenis on July 18, 2021, 07:41:59 pm
Thank you, but no reaction.
The application continues to die silently despite two try ...except blocks
Title: Re: Lazreport kills the application unpredictably
Post by: dseligo on July 18, 2021, 08:55:35 pm
Thank you, but no reaction.
The application continues to die silently despite two try ...except blocks

Are you sure it dies here?

See what you get from this:

Code: Pascal  [Select][+][-]
  1. ShowMessage('1');
  2.     try
  3.       frReport1.LoadFromFile('/data/test1.lrf');
  4.     except
  5.       on E: Exception do ShowMessage(E.Message);
  6.     end;
  7. ShowMessage('2');
  8.      
  9.     try
  10.       frReport1.ShowReport;
  11.     except
  12.       on E: Exception do ShowMessage(E.Message);
  13.     end;
  14. ShowMessage('3');

How complex is your report, what do you use in it? Do you have events attached, do you use scripts, do you use user datasets or DBdatasets?
It is strange you can't replicate your problem in new project. This suggests that the problem is somewhere else in your application.
Title: Re: Lazreport kills the application unpredictably
Post by: Awkward on July 18, 2021, 10:14:44 pm
One stupid thing: Are you sure what have all required units in "USES" part? For me, its: "LR_Class, LR_DSet, lrPDFExport, LR_e_img"
maybe you just miss one of unit there?
Title: Re: Lazreport kills the application unpredictably
Post by: sydenis on July 18, 2021, 10:46:55 pm
How complex is your report
test1.lrf is very simple report with one single text label. See the attachment.
Quote
See what you get from this:
I can see mesages "1" and "2". After - app crash.
Quote
Are you sure what have all required units in "USES" part?
I have only LR_Class in uses. I dont use pdf export, datasets...    this is a verry simpe test report
Title: Re: Lazreport kills the application unpredictably
Post by: dseligo on July 19, 2021, 01:39:09 am
Do you have printer installed? I don't know how that works on Ubuntu, but I had crashes on Windows when there were no printers.
Also, check if process is still listed:
Code: Bash  [Select][+][-]
  1. ps afx | grep your_app_name
Title: Re: Lazreport kills the application unpredictably
Post by: sydenis on July 19, 2021, 07:02:44 am
Also, check if process is still listed:
When the application is not running, the output is as follows:
Code: Pascal  [Select][+][-]
  1. ps afx | grep kzedpass
  2.    6243 pts/1    S+     0:00  |       \_ grep --color=auto kzedpass
When is running (when message "2" is showing):
Code: Pascal  [Select][+][-]
  1. ps afx | grep kzedpass
  2.    6346 pts/0    Ssl+   0:00  |       \_ /data/dev/fbpass/kzedpass
  3.    6388 pts/1    S+     0:00  |       \_ grep --color=auto kzedpass

Quote
Do you have printer installed?
Currently, the printer is not installed on the laptop.  But under debbuger all is fine.
I will try to do all things on Windows tommorow
Title: Re: Lazreport kills the application unpredictably
Post by: Fantablup on July 19, 2021, 09:14:49 am
Just a tip.
You can install a pdf printer instead of a real printer.
I often use this solution.
Title: Re: Lazreport kills the application unpredictably
Post by: sydenis on July 20, 2021, 11:50:23 am
On Windows10 with Xerox printer application works fine.
On Ubuntu with Pantum printer application die
Printers are connected via network
Title: Re: Lazreport kills the application unpredictably
Post by: sydenis on July 23, 2021, 11:34:01 am
After all, this is a very strange thing )
I tried to repeat everything on Lazarus 2.2.   
The same situation. In debug mode, the report opens well. During normal startup, the application crashes.
But in 2.2 now there is a message:
Execution stopped with exit code 1 ($0001)
Title: Re: Lazreport kills the application unpredictably
Post by: sydenis on July 30, 2021, 12:31:24 am
I think I've figured out where is the problem.

The form that called the report had the  property FormStyle set to fsStayOnTop.
If you disable it then the Report opens normally. If it is enabled, the application behaves unpredictably:

in 99% of cases, the application crashes, in 1% - the report opens well.
And there is no chance to intercept the error with a debuger.

Maybe it will be useful to someone )
Title: Re: Lazreport kills the application unpredictably
Post by: jesusr on July 30, 2021, 07:54:27 am
Add to your uses the unit LCLExceptionStackTrace and check if at least it dumps a backtrace. If the program is simple create a test project.
Title: Re: Lazreport kills the application unpredictably
Post by: sydenis on July 30, 2021, 10:54:17 am
After adding LCLExceptionStackTrace, nothing changes in the behavior of the debuger. He behaves the same way as I wrote in the first posts.

It's easy to repeat the situation:
- Create new project
- Put the on the main form TfrReport and TButton component
- Create a primitive report with a single text field
- Code for the Button:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   frReport1.LoadFromFile('my_test_report.lrf');
  4.   frReport1.ShowReport;
  5. end;
- Set the FormStyle = fsStayOnTop property for the main form
- Launch the application and try to open the report

Then set the breakpoint to frReport1.ShowReport and launch the application with the debugger

Then remove the fsStayOnTop and try to launch the application again - all is fine ))
Title: Re: Lazreport kills the application unpredictably
Post by: balazsszekely on July 30, 2021, 11:31:55 am
@sydenis
It works fine for me with Lazarus Trunk/FPC 3.2.0/Win10. There is no crash with fsStayOnTop.
Title: Re: Lazreport kills the application unpredictably
Post by: sydenis on July 30, 2021, 11:41:54 am
@sydenis
It works fine for me with Lazarus Trunk/FPC 3.2.0/Win10. There is no crash with fsStayOnTop.

Are you on linux?
I wrote above that everything worked fine for me on w10
Title: Re: Lazreport kills the application unpredictably
Post by: balazsszekely on July 30, 2021, 11:53:46 am
Quote
Are you on linux?
I wrote above that everything worked fine for me on w10
Yes, I can reproduce it on my linux mint VM(gtk2). Let me see if I can find what cause the exception.
Title: Re: Lazreport kills the application unpredictably
Post by: jesusr on July 31, 2021, 01:34:51 am
I cannot reproduce it here, xubuntu Lazarus 2.2 RC 1 fpc 3.2.0 both in gtk2 and qt5.
Maybe I don't have the same settings, please share a project + report that can reproduce the problem.
Title: Re: Lazreport kills the application unpredictably
Post by: GAN on July 31, 2021, 03:23:20 am
There is no crash with fsStayOnTop / fsSystemStayOnTop.
Linux Mint 19.3 gtk2.
I've tested it in different reports.
Title: Re: Lazreport kills the application unpredictably
Post by: sydenis on July 31, 2021, 09:19:04 am
I guess that Ububntu and Mint are based on different versions of Gnome. On Monday, I will send a project with a report. Sorry I can't do it right now.

I use Ubuntu 20.04.1   Gnome 3.36.7
Title: Re: Lazreport kills the application unpredictably
Post by: sydenis on August 02, 2021, 04:43:44 pm
Here is a test project.
Ubuntu 20.04.1 + Lazarus 2.0.12 (on 2.2 then same situation)
If your report opened immediately without any problems (I also had this), then try closing it and clicking the Button1 a few more times. The report will not open more than once.
Title: Re: Lazreport kills the application unpredictably
Post by: jesusr on August 08, 2021, 05:54:28 pm
it was a little difficult to trigger the problem, but finally I made it. It's not LazReport related, it is a X11 error triggered by gtk (had to guess that too as my IDE was compiled for qt5 and it compiles qt5 apps by default), but I found an easier way to expose the problem using only the IDE (that must be compiled for GTK), do this:

1. Open a file that has some repeated words, for example any pascal file for the word "begin"
2. CTRL+R or open the replace dialog
3. In the "Text to find" field type 'begin' without '
4. In the "Replace with" field type 'Begin' again without '
5. The "Prompt on replace" option must be checked, all other option checkboxes should be clear, all radio options default.
6. Press the button "Replace all"

It will do an annoying blink of windows and will find the first instance showing a confirmation dialog, from there press the "Yes" button and Lazarus will vanish in the ether. If you run Lazarus in a terminal, it will show this:

The program 'lazarus' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadWindow (invalid Window parameter)'.
  (Details: serial 293718 error_code 3 request_code 12 minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)

This is the same error that kills your program.

If you can reproduce this problem with the given instructions then try this:

NOTE: "Remember your changes so your can restore the original code"

1. Open your application
2. Open the project inspector (menu Project->Project inspector);
3. Under "Required Package" double click the LCL package
4. In the new window, under "Files" find and open the gtk2widgetset.inc file
5. Find this function "TGtk2WidgetSet.AppRemoveStayOnTopFlags"
6. Replace this code:

Code: Pascal  [Select][+][-]
  1.         if Assigned(nact) then
  2.         begin
  3.           gdk_window_restack(W^.Window, act, False);
  4.           nact:=W^.Window;
  5.         end
  6.         else begin
  7.           gdk_window_lower(W^.Window); // send to the bottom
  8.           gdk_window_raise(W^.Window); // restore back
  9.         end;
  10.  

with this ( or by nothing, not tested but it was the original code before that change)

Code: Pascal  [Select][+][-]
  1.         gdk_window_lower(W^.Window); // flush it to the bottom, some WMs keep it above
  2.         gdk_window_raise(W^.Window); // bring it back immediatly. But it should keep below the top app
  3.  

Save the file and recompile your program, I was not able to crash it after this, please test and comment.
By the way, I did my tests with current Lazarus (Lazarus 2.3.0 rmain-2_3-255-gfd378d5 FPC 3.2.2 x86_64-linux-gtk2)
TinyPortal © 2005-2018