Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Subscript out of bounds (again)

Author
Message
Abiz
11
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Amsterdam
Posted: 5th Dec 2012 13:51
Got the same error as in the other thread and after debugging found the problem. Here's my (shortened) code fragment:


I get no error when I fill this not-existing array, but I do get an error (not always) when I try to access decor[100].img_number.
In fact the error came when I removed the space before 27 from this instruction:
line 547: if GetRawKeyState ( 27 ) = JA then exit
After removing the space I got the 'out of bounds' for line 433, which in fact was a // remark line.
So, AppGameKit got totally confused.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Dec 2012 14:07
Can you provide a simple compilable example of the error? It is impossible to test this with the code provided.

When you try to replicate the error you will find one of three things happen;
1-You realise you made a mistake in your code
2-You pin down the bug and make it really easy to fix
3-You can't replicate it

I put those in the order they most often happen for me


this.mess = abs(sin(times#))
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Dec 2012 14:23
Defining an array length as 20 and writing to element 100 is not exactly high on the good-practice list!

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Dec 2012 14:28
Ha, I missed that obvious little solution...

Frankly I didn't read through the code much, I'd just like to see people making something that can be compiled and tested as a 'bug' before posting.


this.mess = abs(sin(times#))
Abiz
11
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Amsterdam
Posted: 5th Dec 2012 14:28
Here's the code that works.
Now change nr = 5 to nr = 15
On my Windows XP it crashes. But sometimes you get the out of bounds error.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Dec 2012 14:30
Yes, that's because you have created an array with 10 slots and are trying to use slot 15.

If you want 15 slots you have to dimension the array with 15 slots. It's like buying a size 8 suit and then complaining it doesn't fit you when you're a size 10.


this.mess = abs(sin(times#))
Abiz
11
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Amsterdam
Posted: 5th Dec 2012 14:34
@JimHawkins: Maybe I wasn't clear enough. I reported this because I was surprised that I don't get an error when I fill this non-existing array, but only when I try to access it. And then I get the strangest messages or AppGameKit crashes, which makes you search for the strangest things. Especially as a novice.
I obviously found the solution before I posted here.
Abiz
11
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Amsterdam
Posted: 5th Dec 2012 14:35
@baxslash: Same answer. I know the solution, obviously, but why do I not get an error when I fill it?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Dec 2012 14:41
Abiz, I see what you are trying to say, that you are getting the error not when you fill in the data but when you try to use it. That might be a little confusing.

Still, at least you know the cause of the error and how to avoid it.

I will pass this on.


this.mess = abs(sin(times#))

Login to post a reply

Server time is: 2024-04-27 23:38:38
Your offset time is: 2024-04-27 23:38:38