GLBasic forum

Main forum => GLBasic - en => Topic started by: Stevester on 2011-Aug-10

Title: Array Overflow or Out Of bounds Error?
Post by: Stevester on 2011-Aug-10
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,



Title: Re: Array Overflow or Out Of bounds Error?
Post by: Minion 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)
Title: Re: Array Overflow or Out Of bounds Error?
Post by: Stevester 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.
Title: Re: Array Overflow or Out Of bounds Error?
Post by: Moebius 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.
Title: Re: Array Overflow or Out Of bounds Error?
Post by: hardyx 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.
Title: Re: Array Overflow or Out Of bounds Error?
Post by: mentalthink 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.
Title: Re: Array Overflow or Out Of bounds Error?
Post by: Kitty Hello 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.