Program randomly crashing or getting array out of bounds errors after a few minutes
-
As my FTA like game continues to grow (over 5000 lines of code), I have been trying to figure out why it crashes so much or gives array out out bounds like:
Array index out of bounds.
(Array size: 4, index: 10) Which there is no way the index could be 10. Many times pointing to a “Len” of an array.I notice when I use For Loop Repeat on arrays the program runs fine for a few minutes and then gets an array error at the same place. I have to not use the For Loop Repeat and make the program longer than it needs to be by manually list each array element:
Test=[ ]
Test[0]=CreateSprite()
:
Test[9]=CreateSprite()
:
This works without it creating an array out of bounds error.I’m continuing on slowly with a lot of redesign in my program. However when the program system crashes to when it kicks me out - that is the difficult part to trouble shoot as it happens more intermittently and not really predictable.
I continue on with my program in the hopes system fixes will be made at some point. How often are updates made? I think I’m at version 2.14.
Here is my latest. You can Buy items, press the buttons and you’ll be surprised at how much is working on the menu. Push in/out to zoom, you can collect items and so much more and see them on the inventory big screen.
NXNR18ND51
Tim
-
I had a similar problem using for loop repeat on arrays ended up being somewhere I'd made variable in the loop a global. Took me ages to track it down.
-
Yes I always declare my index variables before a for loop and initialize them for this reason so;
int i = 0 for i = 0 to len(a) loop
this will ensure that the right variable is used.
The random crashes may be due to memory leaks. There are a number of known leaks some of which are not cleared by restarting a program but by restarting Fuze itself. You can keep an eye on this my switching on the memory/fps meter in the preferences.
Updates are supposed to be more frequent than this but I am afraid that things have been slowed down very much by the global pandemic. A lot of these leaks are addressed in the next patch (2.15) which is now very late indeed. I can't go into too much detail except to say that more resources have now been put on this and it will hopefully be out soon.
The other thing that has slowed things down is the Fuze player which is a free version of Fuze that will allow anyone with a Switch to download and play Fuze games which is obviously a very exciting opportunity for us all. For quality control purposes these games will be ones that have been chosen to be showcased by Fuze..
In future it is planned to have more frequent updates. There are a number of bug fix patches due before the next feature patches which will add performance improvements and new tools.
Anyway I am sure that @Jonboy will correct me if I have got any of this wrong!
-
That's a good idea.
-
@pianofire I tried the:
“int i = 0
for i = 0 to len(a) loop”And still got got the array out of bounds but since all of my previous For Loop Repeat counters always used i and went from For i = 0 to 10 Loop...Repeat, in the last part of my program that the array out of bounds happened on I changed the variable i to something else like m or n and I did not see the array out of bounds issue anymore. All I get now is the system crashes after a couple of minutes which will require further investigation.
BTW: the system crashes are not memory leak issues as I have the FPS / memory display option turned on while developing the game. No drops in ram.
The software was closed because an error occurred.
[OK]
Tim
-
@pianofire I'm wondering if declaring the int index variable for the For Loop Repeat statements OR changing the index variable for ALL For Loop Repeat statements is necessary or just make changes to those that are different (For i=0 to 9), (For i=0 to 3)...
-
@tdg8934 If you are using different control variables then it shouldn't be necessary. I tend to always use i,j,k and make them local by declaring them.
-
@pianofire currently I have int declarations for every variable that has a = and a number following (int Coins = 200). I also have an int declaration before every For Loop Repeat section (int I=0 For i = 0 to 10 Loop...) (int I=5 For i=5 to 9 Loop...)
The play Notes music function also uses and index i in its Len array For Loop Repeat section with int declaration. If I don’t change index i to something else like k the program errors its the Len array related For Loop Repeat section.
It works with a declaration k index but not sure why just using a declaration i wouldn’t be good enough. Oh well...moving on!
-
If you have multidimensional arrays and they're not static then
len()
goes crazy!Try this;
array a[2][3] array b[2][3] // This can just as easily be len( a ) / len( a[x] ) it doesn't matter. for x = 0 to 2 loop for y = 0 to 3 loop a[x][y] = 1 repeat repeat printAt( 0, 0, "Cols A: ", len( a[0] ) ) printAt( 0, 1, "Rows A: ", len( a ) ) printAt( 0, 2, "Cols B: ", len( b[0] ) ) printAt( 0, 3, "Rows B: ", len( b ) ) loop update() repeat
If perhaps you're using
len()
to keep track of certain arrays - it becomes "corrupted" hence you could end up trying to access some things which don't exist.https://fuzearena.com/forum/topic/807/multi-dimensional-array-bug
-
Again this is a know bug that is fixed in the 2.15 patch
-
@pianofire Oh yeah, absolutely! Just as he's dealing with arrays and finding these "weird" array key errors, I felt it worth pointing out. I tend to program this way so it sounded all too familiar to me :)