Recent

Author Topic: Runtime error  (Read 3941 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Runtime error
« on: April 21, 2019, 07:02:59 am »
Getting this error: 'Sigsegv at 403880'

  This happens I think when the procedure "ZeroArray" is called.

I can't see anything wrong with the code and  have no Idea how to track this down.

Can someone help:


Willing to post the code and a data set here or probably on my GDrive.

Code: Pascal  [Select][+][-]
  1.    
  2. Type
  3.  
  4. PData = ^TData;
  5.    TData = record
  6.    ICAO     : String;
  7.    Region   : String;
  8.    Distance : Double;
  9.    end;            
  10.  
  11.  
  12. procedure ZeroArray;
  13.  
  14.   private
  15.   public
  16.   end;
  17.    
  18. Var
  19. Form1: TForm1;
  20.  Data   : Array of TData;  
  21.  
  22. implementation
  23.  
  24. procedure TForm1.ZeroArray;
  25.   Var i : Integer = -1;
  26.    begin
  27.     for i := Low(Data) to High(Data) do begin
  28.         Data[i].ICAO := '';
  29.         Data[i].Region := '';
  30.         Data[i].Distance :=0;
  31.      end;
  32.    end;                
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Runtime error
« Reply #1 on: April 21, 2019, 07:17:16 am »
There is no memory allocated for the array.  You need to use SetLength for the array to actually exist.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Runtime error
« Reply #2 on: April 21, 2019, 07:31:35 am »
@440bx


procedure TForm1.FormCreate(Sender: TObject);
    begin
       SetLength(Data,10);
       ZeroArray; 
  end;

I setLength in FormCreate and execute ZerroArray and never get the error there.
 
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Runtime error
« Reply #3 on: April 21, 2019, 07:38:35 am »
Do you know how to debug your executable ? ... step through code, set breakpoints and such ?
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Runtime error
« Reply #4 on: April 21, 2019, 07:47:30 am »
Do you know how to debug your executable ? ... step through code, set breakpoints and such ?

Yes I use the debugger and step thru the code.

However when it gives me  'Sigsegv at 403880' and I don't see anything in the code I' at a loss on how to deas with 'Sigsegv at 403880'
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Runtime error
« Reply #5 on: April 21, 2019, 07:50:48 am »
Now I'm getting an 'Access Violation'?

What does that mean.

FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Runtime error
« Reply #6 on: April 21, 2019, 07:59:21 am »
Now I'm getting an 'Access Violation'?

What does that mean.
It means you are accessing memory which either doesn't exist or attempting to write to memory that is read-only.

Do this, place a breakpoint on the line
Code: Pascal  [Select][+][-]
  1.    for i := Low(Data) to High(Data) do begin
then step through the code using F8. 

If you can step through that "for" loop a few times, place a breakpoint on the "end;" line that is right after the "for" loop then press F9, that will tell you if the "for" loop is executed successfully in its entirety.

Let me know what the result of doing that is.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Runtime error
« Reply #7 on: April 21, 2019, 08:08:29 am »
@440bx

Done; Goes thru ZeroArray  successfully when executed from FormCreate on startup.
And it was executed when called again from a procedure.


FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Runtime error
« Reply #8 on: April 21, 2019, 08:19:12 am »
@440bx

Done; Goes thru ZeroArray  successfully when executed from FormCreate on startup.
And it was executed when called again from a procedure.
That sounds good.  Now you know that part of your code is working. 

Your next step should probably be to step through whatever follows the call to that function.  Eventually, you'll hit the function/procedure where the problem is then, you can step through each line of that function/procedure which will let  you know which line is causing the violation.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Runtime error
« Reply #9 on: April 21, 2019, 08:26:01 am »
Yea, that's what I have been doing for the past two days.

 If there is no way to find the 'Sigsegv at 403880' ? Why do they give it yo us.

Could just say : "Unknown Run time error, Anybody's guess."



FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Runtime error
« Reply #10 on: April 21, 2019, 08:53:39 am »
Yea, that's what I have been doing for the past two days.

 If there is no way to find the 'Sigsegv at 403880' ? Why do they give it yo us.

Could just say : "Unknown Run time error, Anybody's guess."
When the exception occurs while debugging, you can open the call stack window and see which one of your functions caused the problem. 

Let the exception occur while debugging. When the debugger tells you that a violation occurred it will stop.  At that time you open the call stack window and, there among a number of other addresses, you'll see the name of your function that caused the problem.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

julkas

  • Guest
Re: Runtime error
« Reply #11 on: April 21, 2019, 10:40:08 am »
General advice from Pascal beginner

1. I think for dynamic array it would be better
Code: Pascal  [Select][+][-]
  1. for i := 0 to Length(Data)-1 do

2. Enable range checking, overflow checking, assertions, hints, warnings options in Debug mode.

3. Use assertions in critical sections of your code.

4. Carefully examine warnings and hints compiler messages.

Good luck.
« Last Edit: April 21, 2019, 10:43:21 am by julkas »

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Runtime error
« Reply #12 on: April 21, 2019, 10:52:35 am »
1. I think for dynamic array it would be better
Code: Pascal  [Select][+][-]
  1. for i := 0 to Length(Data)-1 do
That's not better and the reason is, if you do it that way,_ you_ have to remember to subtract 1.  Using High and Low is the best way because the compiler keeps track of the array bounds for you.  There is nothing to remember, IOW, no room (or very little room) for mistakes.

The rest of the advice you gave is generally good.  I say generally because, in the specific case of range checking, there will be times when you don't want the compiler to do range checking.

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Runtime error
« Reply #13 on: April 21, 2019, 11:16:17 am »
Thanks
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

julkas

  • Guest
Re: Runtime error
« Reply #14 on: April 21, 2019, 11:19:57 am »
That's not better and the reason is, if you do it that way,_ you_ have to remember to subtract 1.  Using High and Low is the best way because the compiler keeps track of the array bounds for you.  There is nothing to remember, IOW, no room (or very little room) for mistakes.

May be.

Quote
For dynamic arrays, however, Low always returns 0, and High always returns the length minus one. This implies that for an empty array High returns -1 (which, when you think about it, is a strange value, as it is lower than that returned by Low).

Low, High => 2 functions calls vs Length => 1 call in performance terms.
« Last Edit: April 21, 2019, 11:22:15 am by julkas »

 

TinyPortal © 2005-2018