YYC error: second index out of bounds request

LEGOlars

Member
Hi.

I'm working on a large game and I just tried out the YYC instead of VM. Most things work perfectly, but I get this error:


___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Other Event: User Defined 15
for object objButtonListGraphicsQuick:

second index out of bounds request 0,6 maximum size is 1
############################################################################################
--------------------------------------------------------------------------------------------
called from - gml_Object_objButtonListGraphicsQuick_Other_25 (line 82)
called from - gml_Object_objMenuWidgetController_Other_13 (line 79)
called from - gml_Script_scrMenuLoad (line 169)
called from - gml_Object_objButtonSettingsGFX_Other_11 (line 4)
called from - gml_Object_objMenuWidgetController_Step_0 (line 166)

While trying to figure out what the problem is, I narrowed the code down to just this to reproduce the same error:

Code:
for (var i = 0; i < buttons; ++i) {
    with(button_id[i]) {
        // something happens
    }
}
Ok so I guess one of the button_id's doesn't exist. Nope, I can run this code without getting an error:
Code:
for (var i = 0; i < buttons; ++i) {
    if !instance_exists(button_id[i]) show_error("one of the buttons doesn't exists", true);
}
Then I added show_message throughout the loop to figure out exactly where it crashes...
Code:
var g = 0;
for (var i = 0; i < buttons; ++i) {
    show_message("button_id is an instance, not an object_index: "+string(button_id[i]>1000)); //make sure that is is an instance id, not an object_index
    if instance_exists(button_id[i]) {
        show_message("button exists "+string(i)); //yup, button 0 it exists
        g = 0;
        with(button_id[i]) {
            show_message("button executes some code "+string(i)); //all good for button 0
            if g>0 show_error("Somehow -with- became a loop for multiple instances ...", true); //nope, this error doesn't show
            g++;
        }       
        //  ----->            but it crashes before showing the next message... (at i = 0)    <------
        show_message("button finished executing code "+string(i));
    }
    show_message("i goes ppppppp++");
}
So it crashes inside the before reaching i=1, but the "button executes some code" works fine and it's confirmed that the button_id is an (existing) instance and the with(button_id i ) only executes for that single instance.

I'm absolutely clueless where to go from here. This piece of code works fine as well when building with VM. And I did clear the cache multiple times before building with YYC.

Anyone experienced something similar and/or has an idea where to go from here?

Any help is appreciated!
 

rytan451

Member
It looks like you're accessing an array beyond its bounds. Is buttons set to the length of the array button_id?
 

LEGOlars

Member
Ok I figured how to fix it, but I'm not sure if I should file this as a bug report to YYG.

So this is more or less the stuff that happens before that piece of code with arbitrary values:
GML:
event_user(0); //in this user event, all the button ids get created

//Then I add some extra variables to the button_ids
var at = 0;
button_id[at].newvar = 3;
at++;
button_id[at].newvar = 3;
at++; //etc..
The problem was solved by using accessors. So:

GML:
event_user(0); //in this user event, all the button ids get created
//Then I add some extra variables to the button_ids
var at = 0;
button_id[@at].newvar = 3;
at++;
button_id[@at].newvar = 3;
at++; //etc..
Now everything works.

I remember reading something about not using accessors will copy the array for a moment, but I can't really figure out why that would cause an error in this case.

I'm happy it works, but also interested if someone can explain to me why the problem was there in the first place.
 
Top