Search Unity

GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced)

Discussion in 'Immediate Mode GUI (IMGUI)' started by FedeStefan, May 23, 2019.

  1. FedeStefan

    FedeStefan

    Joined:
    Aug 15, 2018
    Posts:
    221
    So i've wanted to test my game today, and when i got in and made a room, i opened my pause menu and everythings broken.


    And the error is
    GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced).


    Heres my full gui script:

    Code (CSharp):
    1.     void OnGUI(){
    2.         GUI.skin = guiSkin;
    3.         GUI.Label(new Rect(Screen.width-190, Screen.height-80, 190, 20), " Tab - pause menu");
    4.  
    5.         GUI.color = new Color(1, 1, 1, 0.7f);
    6.         if(isPaused){
    7.             GUI.color = new Color(1, 1, 1, 0.7f);
    8.             GUI.Window (0, new Rect (Screen.width/2 - 250, Screen.height/2 - 210, 500, 500), MainMenu, "Room: " + PhotonNetwork.room.name + " | Game Mode: " + gameMode);
    9.         }
    10.  
    11.         //Display round countdown timer
    12.         float roundedRestSeconds = Mathf.CeilToInt(currentRoundTime);
    13.         int displaySeconds = Mathf.FloorToInt(roundedRestSeconds % 60);
    14.         int displayMinutes = Mathf.FloorToInt((roundedRestSeconds / 60)%60);
    15.         string niceTime = string.Format("{0:00}:{1:00}", displayMinutes, displaySeconds);
    16.  
    17.         GUI.Box(new Rect(Screen.width/2 - 50, 45, 100, 30), niceTime);
    18.  
    19.         //Display Team Scores
    20.         if(gameMode == "TDM"){
    21.             GUILayout.BeginArea(new Rect(Screen.width/3 - 100, 45, 200, 30));
    22.             GUILayout.BeginHorizontal("box", GUILayout.Width(200), GUILayout.Height(30));
    23.             GUI.color = team_1_Color;
    24.             GUILayout.Label(team_1.teamName + ":");
    25.             GUILayout.Space(5);
    26.             GUI.color = Color.white;
    27.             GUILayout.Label(team1Score.ToString());
    28.             GUILayout.EndHorizontal();
    29.             GUILayout.EndArea();
    30.  
    31.             GUILayout.BeginArea(new Rect(Screen.width - Screen.width/3 - 100, 45, 200, 30));
    32.             GUILayout.BeginHorizontal("box", GUILayout.Width(200), GUILayout.Height(30));
    33.             GUI.color = team_2_Color;
    34.             GUILayout.Label(team_2.teamName + ":");
    35.             GUILayout.Space(5);
    36.             GUI.color = Color.white;
    37.             GUILayout.Label(team2Score.ToString());
    38.             GUILayout.EndHorizontal();
    39.             GUILayout.EndArea();
    40.         }else{
    41.             GUI.color = Color.white;
    42.             GUI.Box(new Rect(Screen.width/2 - 150, 80, 300, 30), "Leading Player: " + leadingPlayer);
    43.         }
    44.  
    45.         GUI.color = Color.white;
    46.  
    47.         if(roundEnded){
    48.             GUI.Box(new Rect(Screen.width/2 - 200, Screen.height/2 - 100, 400, 30), finalText);  
    49.         }
    50.  
    51.         //Fade black screen when returning to Lobby
    52.         FadeScreen();
    53.     }
    54.  
    55.     void MainMenu (int windowID) {
    56.         GUI.FocusWindow(windowID);
    57.         GUILayout.Space (10);
    58.  
    59.         GUILayout.BeginHorizontal();
    60.         Resolutions();
    61.         QualityWindow();
    62.  
    63.         GUI.color = Color.white;
    64.  
    65.         GUILayout.Space (15);
    66.  
    67.         GUILayout.BeginVertical();
    68.         //Select Team to Join
    69.         if(gameMode == "TDM"){
    70.             //Team 1
    71.             if((string)PhotonNetwork.player.customProperties["TeamName"] == team_1.teamName
    72.                 || (!Player && (string)PhotonNetwork.player.customProperties["TeamName"] != "Spectators" || roundEnded)){
    73.                 GUI.enabled = false;
    74.             }else{
    75.                 GUI.enabled = true;
    76.             }
    77.             if(GUILayout.Button(team_1.teamName)){
    78.                 //Kill current player if exist
    79.                 if(!Player){
    80.                     SpawnPlayer(team_1.teamName);
    81.                 }else{
    82.                     SwapTeams(team_1.teamName);
    83.                 }
    84.                 isPaused = false;
    85.                 //Player joined team, notify everyone
    86.                 gameObject.SendMessage("PlayerJoinedTeam", team_1.teamName, SendMessageOptions.DontRequireReceiver);
    87.             }
    88.  
    89.             //Team 2
    90.             if((string)PhotonNetwork.player.customProperties["TeamName"] == team_2.teamName
    91.                 || (!Player && (string)PhotonNetwork.player.customProperties["TeamName"] != "Spectators" || roundEnded)){
    92.                 GUI.enabled = false;
    93.             }else{
    94.                 GUI.enabled = true;
    95.             }
    96.             if(GUILayout.Button(team_2.teamName)){
    97.                 //Kill current player if exist
    98.                 if(!Player){
    99.                     SpawnPlayer(team_2.teamName);
    100.                 }else{
    101.                     SwapTeams(team_2.teamName);
    102.                 }
    103.                 isPaused = false;
    104.                 //Player joined team, notify everyone
    105.                 gameObject.SendMessage("PlayerJoinedTeam", team_2.teamName, SendMessageOptions.DontRequireReceiver);
    106.             }
    107.         }else{
    108.             //Join game with Deathmatch mode
    109.             if(Player || (string)PhotonNetwork.player.customProperties["TeamName"] != "Spectators"){
    110.                 GUI.enabled = false;
    111.             }else{
    112.                 GUI.enabled = true;
    113.             }
    114.             if(GUILayout.Button("Join")){
    115.                 //Kill current player if exist
    116.                 if(!Player){
    117.                     SpawnPlayer(team_1.teamName);
    118.                 }else{
    119.                     SwapTeams(team_1.teamName);
    120.                 }
    121.                 isPaused = false;
    122.                 //Player joined team, notify everyone
    123.                 gameObject.SendMessage("PlayerJoinedTeam", "The War", SendMessageOptions.DontRequireReceiver);
    124.             }
    125.         }
    126.  
    127.         GUI.enabled = true;
    128.  
    129.         if(Player){
    130.             if(GUILayout.Button("Resume")){
    131.                 isPaused = false;
    132.             }
    133.         }
    134.  
    135.         if(GUILayout.Button("Leave Room")){
    136.             LeaveRoom();
    137.         }
    138.         GUILayout.EndVertical();
    139.         GUILayout.EndHorizontal();
    140.  
    141.         GUILayout.Space (10);
    142.         GUILayout.BeginHorizontal();
    143.         if(playerList){
    144.             GUI.color = new Color(0, 20, 0, 0.6f);
    145.         }else{
    146.             GUI.color = Color.white;
    147.         }
    148.         if(GUILayout.Button("Player List", GUILayout.Width(150), GUILayout.Height(25))){
    149.             playerList = true;
    150.         }
    151.  
    152.  
    153.         if(!playerList){
    154.             GUI.color = new Color(0, 20, 0, 0.6f);
    155.         }else{
    156.             GUI.color = Color.white;
    157.         }
    158.         if(GUILayout.Button("Controls", GUILayout.Width(150), GUILayout.Height(25))){
    159.             playerList = false;
    160.         }
    161.         GUILayout.EndHorizontal();
    162.  
    163.         GUILayout.Space (5);
    164.         GUI.color = Color.white;
    165.         scroll3 = GUILayout.BeginScrollView(scroll3, GUILayout.Width(480), GUILayout.Height(300));
    166.         if(!playerList){
    167.             //Show controls
    168.             GUI.color = new Color(20, 20,0, 0.6f);
    169.             GUILayout.Label("Escape - Pause Menu");
    170.             GUILayout.Label("P - Fullscreen");
    171.             GUILayout.Label("T - Chat / Enter - send");
    172.             GUILayout.Label("C - crouch");
    173.             GUILayout.Label("Left Ctrl - prone");
    174.             GUILayout.Label("LMB - fire");
    175.             GUILayout.Label("RMB - aim");
    176.             GUILayout.Label("F - weapon pick up");
    177.             GUILayout.Label("R - reload");
    178.             GUILayout.Label("Left Shift - run");
    179.             GUILayout.Label("Space - jump");
    180.             GUILayout.Label("1/2 - weapon change");
    181.             GUILayout.Label("While selected STW-25 press G for flashlight");
    182.         }else{
    183.             //Show player list***
    184.             GUI.color = new Color(1,1,1,0.8f);
    185.  
    186.             if(gameMode == "TDM"){
    187.                 //Display Team 1 **************************************************************************
    188.                 GUILayout.BeginHorizontal();
    189.                 GUILayout.FlexibleSpace();
    190.                 GUI.color = team_1_Color;
    191.                 GUILayout.Label(team_1.teamName);
    192.                 GUILayout.FlexibleSpace();
    193.                 GUILayout.EndHorizontal();
    194.  
    195.                 foreach(PhotonPlayer player in allPlayers){
    196.                     if((string)player.customProperties["TeamName"] == team_1.teamName){
    197.                         if(PhotonNetwork.player.name == player.name){
    198.                             GUI.color = Color.yellow;
    199.                         }else{
    200.                             GUI.color = Color.white;
    201.                         }
    202.                         GUILayout.BeginHorizontal("box");{
    203.                             GUILayout.Label(player.name, GUILayout.Width(150));
    204.                             GUILayout.Label("Kills: " + ((int)player.customProperties["Kills"]).ToString(), GUILayout.Width(115));
    205.                             GUILayout.Label("Deaths: " + ((int)player.customProperties["Deaths"]).ToString(), GUILayout.Width(115));
    206.                             GUILayout.FlexibleSpace();
    207.                             if(player.customProperties["Ping"] != null){
    208.                                 GUILayout.Label("Ping: " + ((int)player.customProperties["Ping"]).ToString());
    209.                             }
    210.                             GUILayout.EndHorizontal();}
    211.                     }
    212.                 }
    213.                 //*************************************************************************************
    214.  
    215.                 //Display Team 2 **************************************************************************
    216.                 GUILayout.BeginHorizontal();
    217.                 GUILayout.FlexibleSpace();
    218.                 GUI.color = team_2_Color;
    219.                 GUILayout.Label(team_2.teamName);
    220.                 GUILayout.FlexibleSpace();
    221.                 GUILayout.EndHorizontal();
    222.  
    223.                 foreach(PhotonPlayer player in allPlayers){
    224.                     if((string)player.customProperties["TeamName"] == team_2.teamName){
    225.                         if(PhotonNetwork.player.name == player.name){
    226.                             GUI.color = Color.yellow;
    227.                         }else{
    228.                             GUI.color = Color.white;
    229.                         }
    230.                         GUILayout.BeginHorizontal("box");{
    231.                             GUILayout.Label(player.name, GUILayout.Width(150));
    232.                             GUILayout.Label("Kills: " + ((int)player.customProperties["Kills"]).ToString(), GUILayout.Width(115));
    233.                             GUILayout.Label("Deaths: " + ((int)player.customProperties["Deaths"]).ToString(), GUILayout.Width(115));
    234.                             GUILayout.FlexibleSpace();
    235.                             if(player.customProperties["Ping"] != null){
    236.                                 GUILayout.Label("Ping: " + ((int)player.customProperties["Ping"]).ToString());
    237.                             }
    238.                             GUILayout.EndHorizontal();}
    239.                     }
    240.                 }
    241.                 //*************************************************************************************
    242.             }else{
    243.                 //If game mode is Deathmatch, display all players **************************************************
    244.                 GUILayout.BeginHorizontal();
    245.                 GUILayout.FlexibleSpace();
    246.                 GUI.color = Color.green;
    247.                 GUILayout.Label("All Players");
    248.                 GUILayout.FlexibleSpace();
    249.                 GUILayout.EndHorizontal();
    250.  
    251.                 foreach(PhotonPlayer player in allPlayers){
    252.                     if((string)player.customProperties["TeamName"] != "Spectators"){
    253.                         if(PhotonNetwork.player.name == player.name){
    254.                             GUI.color = Color.yellow;
    255.                         }else{
    256.                             GUI.color = Color.white;
    257.                         }
    258.                         GUILayout.BeginHorizontal("box");{
    259.                             GUILayout.Label(player.name, GUILayout.Width(150));
    260.                             GUILayout.Label("Kills: " + ((int)player.customProperties["Kills"]).ToString(), GUILayout.Width(115));
    261.                             GUILayout.Label("Deaths: " + ((int)player.customProperties["Deaths"]).ToString(), GUILayout.Width(115));
    262.                             GUILayout.FlexibleSpace();
    263.                             if(player.customProperties["Ping"] != null){
    264.                                 GUILayout.Label("Ping: " + ((int)player.customProperties["Ping"]).ToString());
    265.                             }
    266.                             GUILayout.EndHorizontal();}
    267.                     }
    268.                 }
    269.             }
    270.             //Display Spctators ****************************************************************************
    271.             GUILayout.BeginHorizontal();
    272.             GUILayout.FlexibleSpace();
    273.             GUI.color = Color.green;
    274.             GUILayout.Label("- Spectators -");
    275.             GUILayout.FlexibleSpace();
    276.             GUILayout.EndHorizontal();
    277.  
    278.             foreach(PhotonPlayer player in allPlayers){
    279.                 if((string)player.customProperties["TeamName"] == "Spectators"){
    280.                     if(PhotonNetwork.player.name == player.name){
    281.                         GUI.color = Color.yellow;
    282.                     }else{
    283.                         GUI.color = Color.white;
    284.                     }
    285.                     GUILayout.BeginHorizontal("box");{
    286.                         GUILayout.Label(player.name);
    287.                         GUILayout.FlexibleSpace();
    288.                         if(player.customProperties["Ping"] != null){
    289.                             GUILayout.Label("Ping: " + ((int)player.customProperties["Ping"]).ToString());
    290.                         }
    291.                         GUILayout.EndHorizontal();}
    292.                 }
    293.             }
    294.             //*************************************************************************************
    295.         }
    296.         GUILayout.EndScrollView();
    297.     }
    298.  
    299.     void  Resolutions(){
    300.         GUILayout.BeginVertical();
    301.         GUILayout.Label("Resolution");
    302.         scroll = GUILayout.BeginScrollView(scroll, GUILayout.Width(140), GUILayout.Height(100));
    303.         GUILayout.BeginVertical();
    304.         for(int a = 0; a < resolutions.Length; a++){
    305.             if(resolutions[a].width == Screen.width && resolutions[a].height == Screen.height){
    306.                 GUI.color = new Color(0, 20, 20, 0.6f);
    307.             }else{
    308.                 GUI.color = new Color(20, 20, 20, 0.6f);
    309.             }
    310.             if(GUILayout.Button(resolutions[a].width + " x " + resolutions[a].height)){
    311.                 resolutionIndex = a;
    312.                 if(Screen.fullScreen){
    313.                     Screen.SetResolution (resolutions[resolutionIndex].width,resolutions[resolutionIndex].height, true);  
    314.                 }
    315.             }
    316.         }
    317.         GUILayout.EndVertical();
    318.         GUILayout.EndScrollView();
    319.         GUILayout.EndVertical();
    320.     }
    321.  
    322.     void QualityWindow(){
    323.         //GUILayout.Space (10);
    324.         GUILayout.BeginVertical();
    325.         GUI.color = Color.white;
    326.         GUILayout.Label("Quality");
    327.         scroll2 = GUILayout.BeginScrollView(scroll2, GUILayout.Width(140), GUILayout.Height(100));
    328.         GUILayout.BeginVertical();
    329.         for (var i = 0; i < QualityNames.Length; i++){
    330.             if(QualityNames[i] == QualityNames[QualitySettings.GetQualityLevel ()]){
    331.                 GUI.color = new Color(0, 20, 20, 0.6f);
    332.             }else{
    333.                 GUI.color = new Color(20, 20, 20, 0.6f);
    334.             }
    335.             if (GUILayout.Button (QualityNames[i]))
    336.                 QualitySettings.SetQualityLevel (i, true);
    337.         }
    338.         GUILayout.EndVertical();
    339.         GUILayout.EndScrollView();
    340.         GUILayout.EndVertical();
    341.     }
    342.  
    343.     void FadeScreen(){
    344.         if(fadeDir == 1){
    345.             fadeValue += fadeDir * 15 * Time.deltaTime;  
    346.             fadeValue = Mathf.Clamp01(fadeValue);  
    347.  
    348.             GUI.color = new Color(1,1,1,fadeValue);
    349.             GUI.DrawTexture(new Rect(0,0, Screen.width, Screen.height), blackScreen);  
    350.  
    351.             GUI.color = Color.white;
    352.             GUI.Label(new Rect(Screen.width/2 - 75, Screen.height/2 - 15, 150, 30), "Loading...");
    353.         }
    354.     }
    And this is how i see my pause menu:
     

    Attached Files:

  2. FedeStefan

    FedeStefan

    Joined:
    Aug 15, 2018
    Posts:
    221
  3. FedeStefan

    FedeStefan

    Joined:
    Aug 15, 2018
    Posts:
    221
  4. FedeStefan

    FedeStefan

    Joined:
    Aug 15, 2018
    Posts:
    221