Author Topic: Array Overflow or Out Of bounds Error?  (Read 2286 times)

Offline Stevester

  • Mc. Print
  • *
  • Posts: 12
    • View Profile
Hi, as a new user I'm finding myself caught out every now and again with my programs exiting without warning.

On investigation its generally been down to me exceeding the array limits such as trying to stick a number in px[10] when it is only defined to px(0-9).

I've managed to sort this out in each case but was wondering why I'm not getting an 'out of bound's or 'array overflow' error pointing at the offending line of code. It would save a lot of time tracing through the program if it pointed straight to the problem area. Am I missing something in settings or debug that does this?

Many thanks,




Offline Minion

  • Mr. Polyvector
  • ***
  • Posts: 229
    • View Profile
Re: Array Overflow or Out Of bounds Error?
« Reply #1 on: 2011-Aug-10 »
Have you tried using debug when compiling ? I find that helps with array overflow (tells me what array has blown, and the whereabouts in the code)

Offline Stevester

  • Mc. Print
  • *
  • Posts: 12
    • View Profile
Re: Array Overflow or Out Of bounds Error?
« Reply #2 on: 2011-Aug-10 »
Thanks for the reply Minion,

I haven't - will have a play with the debug commands tonight. The blown array location in the code is exactly what I'm after.

Even in relatively small programs its not always apparent what the issue is and takes some time to sift through the code.

Cheers.

Offline Moebius

  • Dr. Type
  • ****
  • Posts: 315
    • View Profile
Re: Array Overflow or Out Of bounds Error?
« Reply #3 on: 2011-Aug-10 »
If you have debug mode enabled (Compiler->Debug Mode) then the IDE jumps to the line the program crashed on from an out of index error.
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Offline hardyx

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 505
    • View Profile
Re: Array Overflow or Out Of bounds Error?
« Reply #4 on: 2011-Aug-10 »
You don't get "Out of bounds" error messages because GLBasic compiles to C++ code, and this last language not checks for out of bounds in arrays and overflow errors in operations. Is very fast and good for make fast games and generate code for devices like consoles and phones.  All runtime checks degrades performance in a game with many objects moving arround the screen.
« Last Edit: 2011-Aug-10 by hardyx »

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3375
  • Integrated Brain
    • View Profile
Re: Array Overflow or Out Of bounds Error?
« Reply #5 on: 2011-Aug-11 »
The best way for donĀ“t have troubles whit arrays is :

LEN(myArray[])-1

Whit this never execededs the limits of your array.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10851
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Array Overflow or Out Of bounds Error?
« Reply #6 on: 2011-Aug-16 »
The "out of bounds" is detected on release, too. But the program just exits.
With the debug mode enabled, the errorlog is read. Also, the debug version drops a line about what index you wanted to access.