SOLVED Array out of range at 0?

RujiK

Member
I have a rare bug that I can't squash.

Every blue moon, I occasionally get this error:
Code:
ERROR in
action number 1
of Other Event: User Defined 0
for object obj_beast:


Variable Index [0] out of range [0]
 at gml_Object_obj_beast_Other_10 (line 1732) -             fx = limb_dx[_arm,0];
but I have this in obj_beast's create event:
Code:
for(i=0;i<40;i++) {limb_dx[i,0] = 0;}
And the worst thing is that I can't consistently reproduce this bug. The code works fine 99% of the time but then something changes and then I get this error. Any idea what it could be?

Generous upvotes if that is any incentive. Thanks for your time.
 
D

Deleted member 16767

Guest
Your variable is not equally going together in a balanced way up to a certain number. That's what the debugger is saying.
 

RujiK

Member
Thanks for trying to help, but I don't think I understand what you mean.
Going together in a balanced way? Could you elaborate on that?

My impression from the debugger is that array[0,0] is somehow out of bounds, which shouldn't be possible since 0,0 is defined in the create event.
 

drandula

Member
What version are you using?
In beta 2.3.2 this should be fixed, I have had similar issues with 2.3.1, bugs in arrays.
 
What version are you using?
In beta 2.3.2 this should be fixed, I have had similar issues with 2.3.1, bugs in arrays.
I'm going to take a guess and say pre-2.3 from the 2D array notation.

EDIT: My guess at the problem is that, at some point, limb_dx is overwritten with a blank array. Granted, I'm using the latest version of GMS2.3 so error codes might not be identical, but trying the following produces a similar error code:
GML:
arr = [];
show_debug_message(arr[0][0]);
Push :: Execution Error - Variable Index [0] out of range [0] - -1.arr(100091,0)
 
D

Deleted member 16767

Guest
We haven't seen the rest of the code but if you ++ it then it should go up to (maybe 40?) from 0,1,2,3 and so on. If there's some interrupting it, then it can't go up. That's what I meant by equally going together and balanced (the one that is the variable and the target). That's my guess anyway. I have no idea how you do your creatures, it's awesome btw, I'm just guessing here.
 
if you use array = []; anywhere and try to access array[0], it will throw a crashing error.
Does it crashes it you try array[i][0] = 0; too?

By the way, where did you learn to draw such awesome iso pixel art? I find the resources painfully scarce on the subject...just elbow grease and hours, or there's a Mr. Myagi somewhere I should know of? :)
 

chamaeleon

Member
I like to try to replicate the look of an error message exactly when I can. I can get exactly the same kind of error message with this code
GML:
var foo;
//foo[0, 0] = "abc";
foo[1, 0] = "def";
var bar = foo[0, 0];
show_debug_message(bar);
Code:
############################################################################################
ERROR in
action number 1
of Create Event
for object obj_generic:

Variable Index [0] out of range [0]
at gml_Object_obj_generic_Create_0 (line 6) - var bar = foo[0, 0];
############################################################################################
gml_Object_obj_generic_Create_0 (line 6)
I also get it with
GML:
var foo = ["abc"];
var bar = foo[0, 0];
show_debug_message(bar);
Setting foo to an empty array (var foo = []) introduces extra error content on the line indicating out of range, which makes me think that when you encounter it, your limb_dx variable is a non-empty one-dimensional array. My first attempt to fix it would be to find any assignments to it, and possibly look for @-accessor changes.
GML:
var foo;
foo[0, 0] = "abc";
bug(foo);
var bar = foo[0, 0];
show_debug_message(bar);
GML:
function bug(a) {
    a[@ 0] = "abc";
}
 
Last edited:

RujiK

Member
@drandula I'm using 2.3.1. I actually tried the beta but I got the same error.
@nacho_chicken I'm just slow to update my notation :p I searched every reference for limb_dx but could find nothing that might re-write it.
@mikix There are around ~5000 lines of related code so it's not really practical to post them. I'm glad you like my monsters.
@Slow Fingers array[a][0] also crashes. I never took any special training for isometric art. If you can draw good pixel art, the perspective doesn't make much of a difference. Just boring old practice.
@chamaeleon Thank you for that detailed response. I think you're right about the 2d array somehow being converted into a 1d array. I looked everywhere for a possible conversion, but I couldn't find one.

HOWEVER, I went ahead and converted my 2d limb_dx[a,b] array into a 1d limb_dx[a] array and that fixed it. Uh... WHAT!? Again, I could find no 1d references to my 2d array but it seems to work if it's 1d instead of 2d...


A little more details on what I'm doing:

So I'm making a model viewer and every time you switch models there is about a 1/1000 chance the game will crash with the limb_dx error. I can find no pattern to what causes it but now that it's solved, I don't really care.

Thanks for all of your help! Especially to chamaeleon with the 1d vs 2d idea. Solved (I guess)
 

drandula

Member
Huh, maybe they fixed the problem for [x][y]... arrays but somehow [x,y] type of writing wasn't affected?
But good to hear your problem going away :)
edit. And looking good! đź‘Ť
 
Last edited:
Top