Recent

Author Topic: Following code crashes application  (Read 2796 times)

ertank

  • Sr. Member
  • ****
  • Posts: 274
Following code crashes application
« on: April 23, 2018, 12:13:30 pm »
Hello,

I am using
Code: [Select]
fpc 3.1.1/trunk svn revision 38804 2018-04-22
lazarus 1.9.0/trunk svn revision 57163 2018-01-27
Target is arm-wince executable.

Having just two forms in the project. Following code crashes application. First screen task bar starts to flicker. After several seconds message displayed as "application project1.exe encountered a serious error and must shut down."
Code: [Select]
uses
  Unit2;

{ TForm1 }

procedure Log(const Value: string);
var
  FileName: string;
  F: TextFile;
  Prefix: string;
begin
  FileName := ExtractFilePath(Application.ExeName) + FormatDateTime('yyyy-mm', Now()) + '.log';
  AssignFile(F, FileName);
  {$I-}
  if FileExists(FileName) then Append(F) else ReWrite(F);
  if IOResult <> 0 then Exit();
  Prefix := FormatDateTime('yyyy-mm-dd hh:nn:ss   ', Now());
  WriteLn(F, Prefix + Value);
  CloseFile(F);
  {$I+}
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Top := 20;
  Left := 20;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Form: TForm2;
begin
  Log('1');
  Form := TForm2.Create(Self);
  try
    Log('2');
    Self.Hide();
    Log('3');
    Form.ShowModal();
    Log('4');
  finally
    Form.Free();
  end;
end;

In log file, I read 1, 2, 3 written. There is no 4.

Same error displayed if I try to display Form2 window using "Form.Show()" instead of "Form.ShowModal". Sample project to reproduce can be found attached.

Any help is appreciated.

Edit: Here is a video for understanding the problem. In the video, I did not hide Form1 in order to "feel" how Form2 behaves.
http://s3.dosya.tc/server15/ttfrxy/VID_20180423_134040.mp4.html
« Last Edit: April 23, 2018, 12:57:51 pm by ertank »

WooBean

  • Full Member
  • ***
  • Posts: 229
Re: Following code crashes application
« Reply #1 on: April 23, 2018, 01:15:53 pm »
@ertank

Hi,
just modify your procedure TForm1.Button1Click(Sender: TObject) as below:

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.Button1Click(Sender: TObject);
  3. var
  4.   Form: TForm2;
  5. begin
  6.   Log('1');
  7.   Form := TForm2.Create(Self);
  8.   Form.visible := False; //for modal usage a form must be non-visible at first
  9.   try
  10.     Log('2');
  11.     Self.Hide();
  12.     Log('3');
  13.     Form.ShowModal();
  14.     Log('4');
  15.   finally
  16.     Form.Free();
  17.     Self.Show(); //just to have something visible
  18.   end;
  19. end;
  20.  

WooBean
« Last Edit: April 23, 2018, 01:22:39 pm by WooBean »
Platforms: Win7/64, Linux Mint Ulyssa/64

ertank

  • Sr. Member
  • ****
  • Posts: 274
Re: Following code crashes application
« Reply #2 on: April 23, 2018, 01:25:58 pm »
Hello WooBean,

Same error displays using your code. Most likely this is something else.
If you can watch video link I provided, you will see that same error is displayed even if I use Show and not use any "modal". (Behavior is slightly visible if I use Show)

I suspect, Top and Left properties of the Form2 is changing (reducing) so much that it is out of bounds of Integer and that kills the application. I have no idea why this happens though? Wild and non-educated guess: Anything to do with PPI (aka DPI)?

Thanks.

WooBean

  • Full Member
  • ***
  • Posts: 229
Re: Following code crashes application
« Reply #3 on: April 23, 2018, 02:29:05 pm »
@ertank

Once again.
I tested your code but in different environment: Laz. 1.8.0, FPC 3.0.4, win32, LCL widgetset, optimization level=0 and enabled debug info. It works for me.
My amendments are not needed as  its goal was achived in unit2.

Problem is not in the application but is widgetset specific.

WooBean



Platforms: Win7/64, Linux Mint Ulyssa/64

ertank

  • Sr. Member
  • ****
  • Posts: 274
Re: Following code crashes application
« Reply #4 on: April 23, 2018, 03:30:26 pm »
Hello WooBean,

Would you advise if Lazarus 1.8.0 SVN revision number as well as fpc 3.0.4 svn revision number, please?

I suspect there has been some changes between your release and mine that gives me troubles.

Thank you.

WooBean

  • Full Member
  • ***
  • Posts: 229
Re: Following code crashes application
« Reply #5 on: April 23, 2018, 04:13:25 pm »
Hello WooBean,

Would you advise if Lazarus 1.8.0 SVN revision number as well as fpc 3.0.4 svn revision number, please?

I suspect there has been some changes between your release and mine that gives me troubles.

Thank you.

It will not help you, but anyway - for compiling I used officially distributed Laz. 1.8.0 SVN rev. 56594, FPC 3.0.4. - no SVN.
This is from "About Lazarus" info. SVN numbering and presenting in IDE seems odd for me.
The main difference from original code was changing a platform target, processor and widgetset.

WooBean
Platforms: Win7/64, Linux Mint Ulyssa/64

ertank

  • Sr. Member
  • ****
  • Posts: 274
Re: Following code crashes application
« Reply #6 on: April 23, 2018, 08:25:37 pm »
As it is indicated before. Problem is somewhere in LCL and on Lazarus side.

I have downloaded setup and tested 1.8.2 and it failed.
I have downloaded setup and tested 1.8.0 and it failed.
Then I reverted back to my known to be working version and I confirm that I have no problem and everything works on lazarus/trunk svn 52504 (that is an old, version displayed as 1.7.0)

So, there are some changes between svn 52504 and 56594 that breaks displaying forms (modal or normal) created at run-time.

Once I have time, I will try to find exact modification and post in here.

Just for the record. Problem cannot be observed on Win32 platform (aka regular windows) it does appear on handheld devices running WindowsCE OS.

Thanks.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Following code crashes application
« Reply #7 on: April 24, 2018, 02:43:49 am »
Try createNew(Self) instead;

Maybe the form is trying to access resources that do not exist ?
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018