1. Hey! Guest! The XXX GMC Jam will take place between August 24th, 12:00 UTC (Friday noon) and August 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Windows Game occasionally freezes at random on room transitions

Discussion in 'Programming' started by atrus159, Aug 8, 2018.

  1. atrus159

    atrus159 Member

    Joined:
    Aug 8, 2018
    Posts:
    26
    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;
        }
    }
    
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,021
    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?
     
  3. atrus159

    atrus159 Member

    Joined:
    Aug 8, 2018
    Posts:
    26
    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.
     
  4. atrus159

    atrus159 Member

    Joined:
    Aug 8, 2018
    Posts:
    26
    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.
     
  5. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    1,609
    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.
     
  6. atrus159

    atrus159 Member

    Joined:
    Aug 8, 2018
    Posts:
    26
    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.
     
  7. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    1,609
    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?
     
  8. atrus159

    atrus159 Member

    Joined:
    Aug 8, 2018
    Posts:
    26
    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).
     
  9. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    1,609
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice