Recent

Author Topic: Segmentation fault when opening a form by ShowModal [Solved]  (Read 1340 times)

BrokenMemory

  • New Member
  • *
  • Posts: 13
Segmentation fault when opening a form by ShowModal [Solved]
« on: August 26, 2020, 03:38:20 pm »
Greetings,I was doing a Computer Science project,a segmentation fault comes up when I try to show Form 4 by using a button on Form 2,I did add unit 4 on the Uses on Form 2,the code is as follow


Code: Pascal  [Select][+][-]
  1. procedure TForm2.Button2Click(Sender: TObject);
  2. begin
  3.   form4.Showmodal;
  4. end;
  5.  

Thank you.

Edit:I forgot to mention the error message,it's as follow

Code: Pascal  [Select][+][-]
  1. {------------------------------------------------------------------------------
  2.   procedure TCustomForm.Show;
  3. ------------------------------------------------------------------------------}
  4. procedure TCustomForm.Show;
  5. begin
  6.   if Application.Scaled and Scaled and (Monitor.PixelsPerInch<>PixelsPerInch) then
  7.     AutoAdjustLayout(lapAutoAdjustForDPI, PixelsPerInch, Monitor.PixelsPerInch,
  8.       Width, MulDiv(Width, Monitor.PixelsPerInch, PixelsPerInch));
  9.  
  10.   Visible := True;
  11.   BringToFront;
  12. end;
  13.  
« Last Edit: August 26, 2020, 04:21:50 pm by BrokenMemory »

Handoko

  • Hero Member
  • *****
  • Posts: 5513
  • My goal: build my own game engine using Lazarus
Re: Segmentation fault when opening a form by ShowModal
« Reply #1 on: August 26, 2020, 03:48:14 pm »
Segmentation fault is one of the hardest to fix errors. You only showed some lines of code and that is not enough for us to inspect the problem. Can you provide us the whole source code? If you're not willing to publicize the whole project, you can write a demo project that showing that issue.

Create a new folder, copy and paste all the necessary files to there except: the binary (exe file), *.bak, lib and backup folders. Compress the folder and send the zip here.

Generally these things can cause a segmentation error:
- Calling a method of an uninitialized or nil object
- Freeing an object that has not been initialized
- Pointer points to wrong memory location
- Trying to read memory location that is prohibited
- Writing to memory location that has not been allocated
« Last Edit: August 26, 2020, 03:58:32 pm by Handoko »

BrokenMemory

  • New Member
  • *
  • Posts: 13
Re: Segmentation fault when opening a form by ShowModal
« Reply #2 on: August 26, 2020, 03:58:23 pm »
Segmentation fault is one of the hardest to fix errors. You only showed some line code and that is not enough for us to inspect the problem. Can you provide us the whole source code? If you're not willing to publicize the whole project, you can write a demo project that showing that issue.

Create a new folder, copy and paste all the necessary files except: the binary (exe file), *.bak, lib and backup folders. Compress the folder and send the zip here.

Generally these things can cause segmentation error:
- Calling method of an uninitialized or nil object
- Freeing object that has not been initialized
- Pointer point to wrong memory location
- Trying to read memory location that is prohibited
- Writing to memory location that has not been allocated

Got it,the whole program is uploaded to Filesend
Link:https://filesend.standardnotes.org/send/x7URCnmKxvCELImXYziR
Key: OTEyNDZhOWU5NzU5MGZhYWUwYmQ

Handoko

  • Hero Member
  • *****
  • Posts: 5513
  • My goal: build my own game engine using Lazarus
Re: Segmentation fault when opening a form by ShowModal
« Reply #3 on: August 26, 2020, 04:00:54 pm »
I got a file not found error when tried to download the file from the link you provided.

BrokenMemory

  • New Member
  • *
  • Posts: 13
Re: Segmentation fault when opening a form by ShowModal
« Reply #4 on: August 26, 2020, 04:02:01 pm »
I got a file not found error when tried to download the file from the link you provided.

The link works well to me,try this

https://filesend.standardnotes.org/send/x7URCnmKxvCELImXYziR

Handoko

  • Hero Member
  • *****
  • Posts: 5513
  • My goal: build my own game engine using Lazarus
Re: Segmentation fault when opening a form by ShowModal
« Reply #5 on: August 26, 2020, 04:03:45 pm »
Sorry my fault. That's actually is 2 lines, which I thought is a single line. Now inspecting your code.

Handoko

  • Hero Member
  • *****
  • Posts: 5513
  • My goal: build my own game engine using Lazarus
Re: Segmentation fault when opening a form by ShowModal
« Reply #6 on: August 26, 2020, 04:13:23 pm »
Problem found. The form4 is not auto created. You can manually generate it at runtime. But this is easier:

Lazarus main menu > Project > Project Options > left panel > Project Option > Forms > right panel > Available forms: > select Form4 > click the arrow to move Form4 to the auto-create panel > Ok

Tested on Linux, problem solved.

BrokenMemory

  • New Member
  • *
  • Posts: 13
Re: Segmentation fault when opening a form by ShowModal
« Reply #7 on: August 26, 2020, 04:17:18 pm »
Problem found. The form4 is not auto created. You can manually generate it at runtime. But this is easier:

Lazarus main menu > Project > Project Options > left panel > Project Option > Forms > right panel > Available forms: > select Form4 > click the arrow to move Form4 to the auto-create panel > Ok

Tested on Linux, problem solved.

Thank you very much,now I can continue my work.

 

TinyPortal © 2005-2018