A GMS2 object depth bug

Symmetrik

Member
I was working on a project in GMS2, then spontaneously out of nowhere I got this error when running the game.

############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object <undefined>:

Pop :: Execution Error - Variable Index [0,-1] out of range [1,0] - -5.<unknown variable>(100004,-1)
at gml_Script___global_object_depths (line 22) - global.__objectID2Depth[ objID ] = global.__objectDepths;
} // end for
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script___global_object_depths (line 22)
called from - gml_GlobalScript_1 (line 1) - __global_object_depths()

So I started to delete objects one by one as this error kept referring to an object each time, then once I've deleted all the objects, this error still persists as the error message above. So essentially the whole project is corrupt and I have to delete it because of this bug.
 

rIKmAN

Member
Does GMS2 keep backups like GMS1 does?
If so you might be lucky and have a backup from before the error appeared.

It looks like its the -1 that's causing the issue though ([0, -1]) - arrays cannot be negative numbers which is why it's out of the acceptable range.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
The issue is with the global objects compatibility script "gml_Script___global_object_depths ". This is a script created for you to deal with depth in an imported 1.4 project and has nothing to do with the objects in the resource tree. Re-import the project and if the error persists, file a bug.
 

rwkay

YoYo Games Staff
YYG Staff
OK I have just fixed it internally here but change your object_set_depth script to

Code:
/// @description Sets the depth of the given object.
/// @param {Number} index The index of the object to change
/// @param {Number} depth The new depth of the object
var objID = argument0;
if (object_exists(objID)) {
    with( objID ) {
        global.__objectID2Depth[id] = argument1;
    } // end with
} // end if
And that should do it - let me know if any issues

Russell

Also change the end of the __global_object_depths script to

Code:
// create another array that has the correct entries
var len = array_length_1d(global.__objectDepths);
global.__objectID2Depth = [];
for( var i=0; i<len; ++i ) {
    var objID = asset_get_index( global.__objectNames[i] );
    if (objID >= 0) {
        global.__objectID2Depth[ objID ] = global.__objectDepths[i];
    } // end if
} // end for
 

Bee

Member
I got this too. How do you access those scripts you are mentioning to edit? They aren't scripts I've written... sorry, relative newbie here.
 

Bee

Member
I think I may have fixed it by creating a new object_set_depth script with your contents. Thank you!
 

Schwee

Member
I had the same error but I fixed it using the solution provided by @rwkay (thanks) but I did have to switch the 'argument1' to 'argument0'. Not sure if that was a typo or if I am missing something, but it seems to run now.
 
Top