• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Help with 'trying to draw non-existing sprite' error w.r.t. depth system

darkly

Member
I am trying to implement a depth system in a top down, four-directional movement game. I have a room with a player object and a few box objects placed about. Both objects are tied to a parent 'depth object' with visible = false; in the create event and draw_self(); in the draw event.

I then have a separate depth sorter object with the following:

Create Event:
Code:
ds_depthgrid = ds_grid_create(2,1);
Clean Up Event:
Code:
ds_grid_destroy(ds_depthgrid);
Draw Event:
Code:
//Resize Grid
var dgrid = ds_depthgrid;
var inst_num = instance_number(par_depthobject);
ds_grid_resize(dgrid,2,inst_num);

//Add Instance Info to Grid
var yy = 0; with(par_depthobject){
    dgrid[# 0, yy] = id;
    dgrid[# 1, yy] = y;
    yy++;
}

//Sort Grid in Ascending Order
ds_grid_sort(dgrid, 1, true);

//Loop
var inst;
yy = 0; repeat(inst_num){
    //pull out id
    inst = dgrid[# 0, yy];
    //draw self
    with(inst)
    {
        event_perform(ev_draw, 0);
    }
    yy++;
}
When trying to run the game, I am hit with the 'trying to draw non-existing sprite' error, in the parent objects' draw event called from the above //Loop section of the depth sorter object's draw event. If I remove the //Loop chunk of code in the above draw event, things seem to be working (albeit with no actual effect) as the debugger shows the ds_grid pulling and sorting variables correctly. The error appears even I remove all instances (player + boxes) in the room editor, so while I don't believe the issue is in the code of these objects, I'm happy to share it if it could help solve the issue.

Been stuck for a minute, any thoughts? For reference, the depth system is based on the following tutorial from FriendlyCosmonautl:
 

Nidoking

Member
The most likely cause I can think of is that there's an instance of par_depthobject (or one of its children) that doesn't have a sprite. What I'd do is put a breakpoint at the start of the loop and step through with the debugger, look at the instance associated with each value of inst that gets pulled out of the grid, and make sure every one of them is something you intended to draw.
 
Top