Windows Game occasionally freezes at random on room transitions

A

atrus159

Guest
Yesterday I added code for doors to transition between rooms. To test the doors I set up a series of 4 rooms with doors between them. The doors all have a room and a door object that they go to, as well as a script for how to arrange the characters upon exiting the door (you control several characters from top down view). Upon clicking on the door, if a character is sufficiently close, it will tell the control object the door that it goes to and then transition to the appropriate room. On room start the control object will check if it has been told a door to go to, and if it does, it will find that door and call its script to arrange all the characters next to it.

This works as intended, except that sometimes on going from one room to another the game will freeze and will need to be force quit. The screen stays black from the fade transition so I assume it freezes before a draw event ever happens. These freezes happen seemingly at random (I have had them on every door, and have also had every door work at some point). I've had it happen as soon as the first door and as late as five minutes after starting the game. I have been completely unable to reliably reproduce this other than by rapidly going back and for through doors for several minutes.

relevant code:

object Door left release event:
Code:
if(clicked_on && !control.paused){
    clicked_on = 0;
    if(distance_to_object(instance_nearest(x,y,pc_character))<=64){
        if(!blocked){
            control.door_out = door_out;
            var myFade = instance_create_layer(0,0,"GUI",room_fade);
            myFade.toGo = room_to;
        }
    }
}
object room_fade draw gui event
Code:
if(t<(tMax+10)){
    t++   
}else{
    control.paused = 0;
    mouse.fixed_camera = 0;
    instance_destroy(self);
    room_goto(toGo);
}
draw_set_alpha(t/tMax);
draw_set_color(c_black);
draw_rectangle(0,0,window_get_width(),window_get_height(),false);
draw_set_alpha(1);
object control room start event
Code:
if(door_out != noone){
    with(door){
        if(object_index == other.door_out){
            script_execute(placement);   
        }
    }
    door_out = noone
}
One of the door placement scripts. There are 4 right now, one for each direction of door and they are identical the same except for placement directions
Code:
camera_set_view_size(mouse.myCamera,640,480);
camera_set_view_pos(mouse.myCamera, x-100,y-150);
    var offset = 0;
with(pc_character){
    direction = 0;
    x = other.x +64;
    y = other.y +65*offset;
    if(offset<=0){
        offset *= -1;   
        offset +=1;
    }else{
        offset    *=-1;
    }
}
 

samspade

Member
I don't see anything wrong in your posted code. (Which doesn't mean there isn't anything.) However, the problem you describe is also more likely to occur with a forever loop of some kind, generally a while loop, but it can also happen with do until and for loops. I would check other code that occurs during a room transition or creation. For example, are you spawning in enemies upon room creation and using a while loop to check if placement is free? Or does your player's movement code use a while loop and is it possible for them to spawn on an object that would place them inside of a 'solid' object?
 
A

atrus159

Guest
Update: I commented out the with block in all of the placement scripts and have been testing it for close to ten minutes. It hasn't broken yet which suggests that the with block is somehow the problem. Adding it back in caused it to break withing 5 minutes.
 
A

atrus159

Guest
update: I have been stepping through the program after every room change. It seems to get through every objects step event successfully. I put a break point on the last step event inside an if statement that checks if its the first frame of a new room. On the frame where the program freezes it gets to that if statement, then I click step over to go to the next event and it freezes. The debugger gets disconnected and I get a little "connection lost" message. It doesn't show the program counter doing anything after that if statement.
 
object control room start event
Code:
if(door_out != noone){
    with(door){
        if(object_index == other.door_out){
            script_execute(placement);  
        }
    }
    door_out = noone
}
What is "door" - is that a door instance or your actual door object? Where do you define door?

Also, where do you set door_out? Is it definitely set to an object_index of a door (maybe you have multiple door objects, can't determine that from your code), as you are trying to compare it with the object_index of whatever "door" is.
 
A

atrus159

Guest
What is "door" - is that a door instance or your actual door object? Where do you define door?

Also, where do you set door_out? Is it definitely set to an object_index of a door (maybe you have multiple door objects, can't determine that from your code), as you are trying to compare it with the object_index of whatever "door" is.
door is the parent class of all doors. The variable door_out is set to whichever door you are supposed to exit out of before a room transition. It is an object index and there is only ever one instance of each child of door. Each specific door in the level is a unique object.
 
door is the parent class of all doors. The variable door_out is set to whichever door you are supposed to exit out of before a room transition. It is an object index and there is only ever one instance of each child of door. Each specific door in the level is a unique object.
ok, that seems to check out fine then.

Have you checked all your Draw Events for infinite loops? What about the fade object, does that have any code that might lock up the game?
 
A

atrus159

Guest
ok, that seems to check out fine then.

Have you checked all your Draw Events for infinite loops? What about the fade object, does that have any code that might lock up the game?
again, I have done a step through and it seems to get all the way through the fade and room transition fine. The freeze happens at the end of the step event before the end-step event. It never gets a draw event in the new room. In my step through I got to the step event of the last object in the room and then had the debugger get abruptly disconnected. The program counter never showed anything past the last step event (which is just an if statement that I made to put a break in).
 
The screen stays black from the fade transition so I assume it freezes before a draw event ever happens.
I put a break point on the last step event inside an if statement that checks if its the first frame of a new room.
I had mistakenly assumed from the above that your code is managing to transition you to the next room but the screen is staying black and locking up at that point, which made me think you had a fade in transition as well for starting the new room, which might have been locking up at the start of the Draw Event.

If you like and you don't mind sharing your project, you can upload it somewhere and post a link, or PM me the location and I'll check it out to see if I can spot anything.
 
Top