• 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!

[Solved] Game freezes on room_goto()?

Nixxi

Member
This is a brand new bug I'm running into and I have no idea how I got it, been over the code several times and I probably just need fresh eyes to look at it. Here's what I have:

rm_Start is the first room to load. It creates one instance of obj_SYS and this object initializes all globals/enums/macros/etc. The object also creates an instance called "obj_StartLogos" that rolls through some images for my collaborators. When it is done it should destroy itself and flag a variable "obj_SYS.b_LogosPlayed" to true. The obj_SYS instance should then create four (4) instances for the player UIs, and go to the next room (rm_HomeScreen) - except, it doesn't get that far. The UI objects are never created and the room never transitions; the game is frozen and unresponsive.

Here's my obj_SYS 'step' code:
Code:
/// @description Start Slides
if !instance_exists(obj_StartLegal) && !b_LegalPlayed {
    // Start Legal Slide
    instance_create_layer(0,0,global.l_HUD_01,obj_StartLegal);
}
if !instance_exists(obj_StartLogos) && !b_LogosPlayed && b_LegalPlayed {
    // Start Logos Rolling
    instance_create_layer(0,0,global.l_HUD_01,obj_StartLogos);
}
if b_LegalPlayed && b_LogosPlayed {
    // Spawn Player Cards
    for (var pc = 0; pc < 4; pc += 1) {
        var TEMP = instance_create_layer(240*pc,0,global.l_HUD_00,obj_PlayerCard_UI);
        with(TEMP) {
            p_PlayerController = pc;
        }
    }
    // Go to the Home Screen
    i_GameStatus = enum_GameState.menu_HomeScreen
    room_goto(rm_HomeScreen);
}
... This is the obj_StartLegal 'step' code:
Code:
/// @description Timing for Legal Screen
if !b_Fade {
    if f_Alpha < 1.00 {
        f_Alpha += 0.02;
    } else if i_Time >= 0 {
        i_Time -= 1;
    } else {
        b_Fade = true;
    }
} else {
    if f_Alpha > 0.00 {
        f_Alpha -= 0.02;
    } else {
        obj_SYS.b_LegalPlayed = true;
        instance_destroy();
    }
}
... And here is my obj_StartLogos 'step' code:
Code:
/// @description Count Slides, Timing, and Alpha
switch i_Slide {
    case 0:
        // NIM Logo
        if !b_Fade {
            if f_Alpha < 1.00 {
                f_Alpha += 0.02;
            } else {
                if i_Time > 0 {
                    i_Time -= 1;
                } else {
                    b_Fade = true;
                }
            }   
        } else {
            if f_Alpha > 0.00 {
                f_Alpha -= 0.02;
            } else {
                i_Slide += 1;
                i_Time = 180;
                b_Fade = false;
            }
        }
        break;
    case 1:
        // GMS2 Logo
        if !b_Fade {
            if f_Alpha < 1.00 {
                f_Alpha += 0.02;
            } else {
                if i_Time > 0 {
                    i_Time -= 1;
                } else {
                    b_Fade = true;
                }
            }   
        } else {
            if f_Alpha > 0.00 {
                f_Alpha -= 0.02;
            } else {
                i_Slide += 1;
                i_Time = 300;
                b_Fade = false;
            }
        }
        break;
    case 2:
        // "Help Wanted"
        if !b_Fade {
            if f_Alpha < 1.00 {
                f_Alpha += 0.02;
            } else {
                if i_Time > 0 {
                    i_Time -= 1;
                } else {
                    b_Fade = true;
                }
            }   
        } else {
            if f_Alpha > 0.00 {
                f_Alpha -= 0.02;
            } else {
                i_Slide += 1;
                i_Time = 60;
                b_Fade = false;
            }
        }
        break;
    case 3:
        // Blackout Room
        if f_Alpha < 1.00 {
            f_Alpha += 0.01;
        } else {
            if i_Time > 0 {
                i_Time -= 1;
            } else {
                i_Slide += 1;
            }
        }
        break;
    case 4:
        // For debug purposes
        b_ShouldHaveFinished = true;
        // Set flag to true
        obj_SYS.b_LogosPlayed = true;
        // Destroy
        instance_destroy();
        break;
    default:
        // For debug purposes
        b_ShouldHaveFinished = true;
        // Set flag to true
        obj_SYS.b_LogosPlayed = true;
        // Destroy
        instance_destroy();
        break;
}
I also have one instance of obj_DEBUG which monitors and draws all the data changes in obj_StartLogos - just before the game freezes the i_Slide variable ticks up to 4, but b_ShouldHaveFinished never gets set to true and the game locks up. Can anyone figure this out?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
The game freezing usually means you have entered into some kind of infinite loop. Run the game in the debugger and add a breakpoint to the point just before the game freezes then step through the code and see what's actually happening.
 

chance

predictably random
Forum Staff
Moderator
Try using the debugger and/or just printing the various variable's values.

Either way, this is probably a coding error -- not a GM technical issue. So it's better in the Programming forum.

edit: Nevermind. Noc beat me to it.
 

Nixxi

Member
Yeah, you guys were right. I had obj_DEBUG for counting how many obj_PlayerCard_UI instances were alive, but the render wouldn't update because there was an instantaneous flood of dupe instances because I didn't have a condition in place to prevent the function from continuing forever after running once. Apparently this prevented the instance_number(obj_PlayerCard_UI) in obj_DEBUG from updating in the Draw Event and thus I didn't realize the count was at a billion instead of zero. :confused:

To fix it I added b_PlayerCards to obj_SYS:
Code:
if b_LegalPlayed && b_LogosPlayed && !b_PlayerCards {
   // Spawn Player Cards
   for (var pc = 0; pc < 4; pc += 1) {
       var TEMP = instance_create_layer(240*pc,0,global.l_HUD_00,obj_PlayerCard_UI);
       with(TEMP) {
           p_PlayerController = pc;
       }
   }
   b_PlayerCards = true;
   // Go to the Home Screen
   i_GameStatus = enum_GameState.menu_HomeScreen
   room_goto(rm_HomeScreen);
}
Was tricky to find because there were no errors in the compile and no asserts during run-time. Thankfully I spotted the instance list in the debugger and figured it out. Thanks guys. :)
 
Top