Recent

Author Topic: (SOLVED) Raising exceptions?  (Read 3522 times)

MJ Haste

  • New Member
  • *
  • Posts: 34
  • An aspiring programmer!
    • MJHaste's YouTube
(SOLVED) Raising exceptions?
« on: December 19, 2014, 07:35:55 pm »
Operating System: Windows 8.1
Lazarus IDE v1.2.4

Hello, random Christmas game I'm working on to show off at college.
Keeping running into similar errors, but I've fixed everyone up to this one.
The program is attached in a .rar.
The problem is caused by this line of code:
Code: [Select]
Reindeer[I2].Named:='N/A';But, I have no clue how to fix it. If I do:
Code: [Select]
Reindeer[I2].Named:=''; it executes fine but ruins another functionality in my code.
I would greatly appreciate any help!

Quote
Project raised exception class 'External: SIGSEGV'.

At address 412F4E03
« Last Edit: December 20, 2014, 02:37:02 pm by MJ Haste »
Programming is my middle name! Wait, no it is not...

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Raising exceptions?
« Reply #1 on: December 19, 2014, 09:55:12 pm »
You are mixing strictly typed/allocated arrays with dynamic arrays.
And you are using magic numbers all over the place.
The easiest fix (not the preferred solution) is to change the routines where you have the parameter 'Var CuFile: array of SFile': change the loop control variable from 1..4 to 0..3.

I see you have different ranges: so in general start and end with 1 less.
E.g.: 1..5 becomes 0..4.
Or 1..2 becomes 0..1.
etc.

And also: when you call one of those routines with parameter SaveN: decrease it with 1.
« Last Edit: December 19, 2014, 10:06:20 pm by eny »
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

MJ Haste

  • New Member
  • *
  • Posts: 34
  • An aspiring programmer!
    • MJHaste's YouTube
Re: Raising exceptions?
« Reply #2 on: December 19, 2014, 10:27:55 pm »
Thanks for the help.
I realise that magic numbers would be a problem for another person (such as yourself) looking at it. But, it's not really a problem for me.

Could you explain why all the loops had to be reduced by one?
And why that fixed the problem?
Just being told what to do is no fun, I like to know why and understand!

Also, could you explain the mixing of arrays?

Thanks a bunch :)
Programming is my middle name! Wait, no it is not...

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Raising exceptions?
« Reply #3 on: December 19, 2014, 10:43:10 pm »
I realise that magic numbers would be a problem for another person (such as yourself) looking at it.
I'm assuming this is meant as a joke.

Dynamic arrays have indices that are zero-based.
Your strictly typed arrays start with index 1.
That is causing the problem.

In the procedure definitions your use dynamic arrays: how big is an 'array of SFile'?
While in the call you pass variable CFile that is strictly defined.
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

MJ Haste

  • New Member
  • *
  • Posts: 34
  • An aspiring programmer!
    • MJHaste's YouTube
Re: Raising exceptions?
« Reply #4 on: December 19, 2014, 11:13:28 pm »
Quote
I'm assuming this is meant as a joke.
No, I thought you were referring to replacing numbers with variables (especially since they're repeated). And, I was saying that this had no real point so I didn't care to make it easier for other people to understand what the numbers represented.
Programming is my middle name! Wait, no it is not...

 

TinyPortal © 2005-2018