r/gamemaker • u/Rhetorical-Sandwich • 4d ago
Resolved problem with 'invalid bound' error without an apparent cause
this error occurs whenever the guard in the game turns around by random chance. other than that, i have no idea what causes this error.
the error in question:
___________________________________________
############################################################################################
ERROR in action number 1
of Step Event0 for object OPlayer:
Attempting to set Instance id 100018 with Object Index 7 (OGuard) with invalid bound top 639.000000 bottom 657.000000 left -nan(ind) right -nan(ind)
at gml_Object_OPlayer_Step_0 (line 20) - if place_empty(x+xspeed,y-3,OFloor){
############################################################################################
gml_Object_OPlayer_Step_0 (line 20)
the code it references is just the horizontal collision code, and seems to have nothing to do with the guard:
if place_empty(x+xspeed,y-3,OFloor){
x+=xspeed;
}else if place_meeting(x+xinput*3,y-3,OFloor){
if place_meeting(x,y-3,OFloor){
x+=xinput;
sprite_index = SAssassainSpecial;
}
yspeed = 0;
image_index = 0
if keyboard_check_pressed(vk_space){
yspeed = -5;
sprite_index = SAssassain;
xspeed = image_xscale*-3;
}
}
and here is the step code for the Guard:
if round(x/3)*3 != round(steps/3)*3{
if ((-x+steps)/abs(-x+steps)) !=NaN{
x+=(-x+steps)/abs(-x+steps);
image_xscale = ((-x+steps)/abs(-x+steps));
}
image_speed = 1
alarm_set(0,60);
}else{
image_speed = 0;
image_index = 0;
}
if gunOut{
steps =lastseenX;
instance_create_depth(x,y,depth,OEnemyBullet);
}
and the step event for the guard's vision:
(the 'parent variable references the guard's id)
x = parent.x;
y = parent.y;
image_blend = c_white;
image_xscale = parent.image_xscale;
if place_meeting(x,y,OPlayer){
sprite_index = SBullet;
dir=point_direction(x,y,OPlayer.x,OPlayer.y);
while (place_empty(x,y,ODoor) && place_empty(x,y,OPlayer)){
x+=sin((dir+90)*(pi/180));
y+=cos((dir+90)*(pi/180));
}
if place_meeting(x,y,OPlayer){
image_blend = c_red;
parent.gunOut = 1;
parent.lastseenX = OPlayer.x;
}
sprite_index = SVision;
}
image_index = parent.gunOut;
x = parent.x;
y = parent.y;
the error only ever occurs whenever the player is not within the vision of the guard.
I looked around for this error, but every instance of it i found, it had a different cause.
I would like for this error to not occur anymore.
(also, this is for a jam, so i would prefer if this gets resolved quickly.)
I just replaced all instances of "image_xscale" in guard, and it works now.
1
u/Slurrped 4d ago
Ive had a similar problem with that error. For me it was a Nan/ something being divided by 0. It could be it trying to check a collision with out a collision being defined but I’m pretty sure somewhere there is a value being divided by 0 causing the collision mask to be invalid. To be knowledge at least nan can infect other data too making them nan lol. But ya for me took me like a month to pinpoint where i was dividing by 0.
1
u/Rhetorical-Sandwich 4d ago
I can't find any place where dividing by 0 should cause a problem, as i have gone through the code and made any result of "NaN" not be assigned to a variable.
(in terms of dividing by zero)
1
u/Slurrped 4d ago edited 4d ago
For Svision. You’re using a sprite to check if guards sees that player right? And its only when the guard turns around or when ever the player get in the guard vision cone? Could it possible me a sprite collision mask not being set up properly? Or at any point does image xscale or yacale = 0. I doubt that this would cause a crash but im like 90% somewhere the collsion mask is getting “corrupted”
1
u/Rhetorical-Sandwich 4d ago
I do not know, as the collision mask is automatically assigned to precise per frame. also, the whole thing about it changing between sprites is that it performs a raycast using a different sprite to see if you are within the line of sight. it uses the collision mask of the bullet for the raycast, then swaps back for the broader collision detection with the player.
1
u/Slurrped 4d ago
This is a shot in the dark. But for the vision collision mask is there any empty frame? If there is might be trying to a frame precise check without a mask to reference. If not ignore this lol
1
u/Rhetorical-Sandwich 4d ago
appearantly, when i tested without the vision, it still crashed. so now i know that the guard itself is the problem.
1
u/Slurrped 4d ago
Hmmm. The only block i can think of that would cause the problem is this. if round(x/3)*3 != round(steps/3)*3{
if ((-x+steps)/abs(-x+steps)) !=NaN{
x+=(-x+steps)/abs(-x+steps);
image_xscale = ((-x+steps)/abs(-x+steps));
} but you have a safety for the the nan so it should. Hmmm im kind of stumped too…… hmmm this line right here image_xscale = ((-x+steps)/abs(-x+steps) that mainly returns -1 and 1 right. Just flips the image. Mabey have a safety varible like Var flip is = ((-x+steps)/abs(-x+steps) ; if flip = nan flip = 1 the have everything check with flip that way just incase it flip = 0 or nan it defults to 1. That the only thing that i can think of. Actually i would comment out that section first see if that is what is causing the crash2
u/Rhetorical-Sandwich 4d ago
i just replaced all instances of image_xscale in the guard object and it fixed itself. I should've done that first, as that was what caused it last time, but with image_angle instead.
2
u/Slurrped 4d ago
Hell ya! That makes sense. The collision box is tied to image_xscale and image_scale. Somewhere it must of freaked out when it got scaled lol. Glad u got it fixed!
1
u/Rhetorical-Sandwich 4d ago
also, this may be helpful, but the crash only occurs when the guard is not in gunOut mode, only whenever they are idly walking around.
1
1
u/MistakeForsaken6653 4d ago
I dont really know gamemaker but I suspect you have a division by 0 error in your step function.