Console message meaning

What exactly means such console message:

“GUI Window tries to begin rendering while something else has not finished rendering! Either you have a recursive OnGUI rendering, or previous OnGUI did not clean up properly.”

The code what causes it to appear is:

public class MenuCode : MonoBehaviour
{
    
    enum menuStates
    {
        mainMenu=0,
        difficultyChoose,
        options,
        geoscape
    }
    menuStates currentMenuState;
    
    public GUISkin geoscapeSkin;

    void Awake()
    {
        currentMenuState=menuStates.mainMenu;
        Screen.showCursor=true;        
    }

    void OnGUI()
    {
        switch(currentMenuState)
        {
            case menuStates.mainMenu:
                createMainMenu();
                break;

            case menuStates.geoscape:
                break;
        }        
    }

    void createMainMenu()
    {
        GUI.skin=geoscapeSkin;
        if(GUI.Button(new Rect(Screen.width/2,Screen.height/2,285,62),"NEW CAMPAIGN")) button1Click();
        GUI.Button(new Rect(Screen.width/2,Screen.height/2+67,285,62),"CONTINUE GAME");
    }
}

Don’t call GUI.Button if you are not putting it within an if test.

I think it would be better to avoid using switch in OnGUI(). OnGUI can be called more then once each frame, and in this scenario your switch has quite an over head.

At this scenario you are better off doing:

void OnGUI()
{
  if ( currentMenuState == menuStates.mainMenu)
  {
    createMainMenu();
    return;
  }

  if ( currentMenuState == menuStates.geoscape)
  {
    // Do what you wanted here
    return;
  }
}