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 / compiler error bug with array out of bounds

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th May 2013 09:31
Tier 1, 108 beta 11.

I searched the google board and I didn't see this listed specifically, but may be related to the issues with UDT arrays. The error reporting is just all jacked up when it comes to them.

I have code broken up into about a dozen source files. One defines my arrays and variables and I have another which fills my arrays with the data I need. I added a new stuff at index 8 but only had the array allocated for 7. Now here's where the problem gets weird.

Sometimes, the app crashes when I compile-run it. Sometimes it will run fine. Sometimes it will run then crash unexpectedly. Other times I'll get an error either during compile or after its running stating that "Array accessed with too few subscripts at line XX in fubar.agc". The line is never anywhere near any code which accesses that array but an entirely different array. Nor does that message really make any sense. My array takes a single subscript so this was very misleading, if the random error line wasn't enough.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th May 2013 13:05
yes, Tier 1, 108 beta 11 is strange,
i get no out of bounds error and it looks like a automatic redim !?
i hope it not write in unreserved memory.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 13th May 2013 16:47
AGK doesn't properly check for out of bounds in Tier 1. I am convinced of this because so many people run into this issue.

Since it is possible to redim an array, the compiler has no way to know if that has been done. So it cannot check to see if a hard coded index is out of bounds for an array.

And it appears that, in Tier 1, it doesn't properly 'know' the correct size of an array (especially one of UDTs) and doesn't always check an index against the size of the array.

At this stage, it is really up to the coder to ensure that indices are not out of range.

And there is at least one google issue regarding this problem.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th May 2013 17:40
"agk" must reserve the memory,each udt is one entry same like a integer. if i want access a entry it knows the limit and i expect
a runtime error if i am out of bounds.
yesterday i missed this runtime error, i create sprites on screen
by user input and this put them into a array and i wonder me because
i see no error.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 13th May 2013 18:19
I think the Tier 1 AppGameKit engine has had trouble properly handling memory for arrays of UDTs. Especially in the dereferencing of UDTs directly (e.g. "x = udtarray[i].somevalue" has frequently been an issue).

This is something they have been working on, I think/hope.

It's probably especially an issue if a string is in the UDT.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th May 2013 18:22
Mine didn't have any strings in the UDT.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 13th May 2013 19:12
Strings aren't a requirement for there being a problem. They just complicate the issue.

Can you show some of your array and variable initializations? For instance, are you making sure to use the 'global' key word for non-arrays? And it doesn't hurt to use it with arrays, even though the dim command theoretically makes them global (I never trusted that).

And maybe some code showing the areas you get the theoretical error messages in (plus/minus 15 lines)?

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th May 2013 06:16
Quote: " For instance, are you making sure to use the 'global' key word for non-arrays?"

Can you explain? I only use global when my variables need to be global. Not all of them do.

The error seemed to come up on this line most times(in various places):


But the problem was with an array called caves[].

And I take it back, my cave UDT does have strings in it.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 14th May 2013 17:36
I meant using global on any variables that are intended to be. Like maybe '_LastDirection'.

There has been a long standing issue with arrays of UDTs.

Instead of directly using the array element (as in '_Equip[_LastDirection].playerFrame') make a local copy of the UDT at _Equip[_LastDirection] and then use that copy in the function call. This was one of the ways I fixed a lot of my UDT array issues.

Something like this for strictly reading the values:


And, to update a value


It's awkward and a pain, but it also might clear up the mystery error.

One of the reasons I finally went over to Tier 2 was because of all the problems that occurred around strings (in general) and UDTs.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th May 2013 00:56
Quote: "It's awkward and a pain, but it also might clear up the mystery error."


Increasing my array size to actually accommodate what I was using has fixed the issue anyway. So it's not really bothering me anymore, I just wanted to bring attention to the problem with the error reporting and maybe figure out why it wasn't picking up the out of bounds. (this is from my zelda clone)

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 15th May 2013 05:13
I think I discussed why it is hard for the compiler to pick up out of bounds.

It has no way to know if something has redimensioned the array after the initial declaration. So there is no way for it to know if an index used is valid.

At execution time, sometimes it appears to not be able to keep track of the size of an array.

But, you should always dimension it for the expected size. And adding a little extra can't hurt.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master

Login to post a reply

Server time is: 2024-05-06 17:57:35
Your offset time is: 2024-05-06 17:57:35