- Home /
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");
}
}
Then it must have something to do with other code, since that code is fine and won't cause any errors by itself.
Answer by GuyTidhar · Jun 28, 2011 at 03:10 PM
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;
}
}
There's nothing wrong with calling GUI.Button without an if statement; it just won't do anything when clicked, that's all. Also, changing switch to if/then won't have any effect at all on performance. It amounts to basically the same thing once the code is compiled.
As far as the switch and if goes - that is generally not true. There are differences, though they are in nano seconds. There are times when switch is better then if. This is not one of them. When you come from an extreme optimization world as I did, you should know what I'm talking about.
Is the extreme optimization world like the Digimon world? 0_0 I kinda wanna go there now. XD
I did say "basically the same thing" for a reason. There may be a nanosecond here or there, but since it has no effect whatsoever on the framerate, you're not better off using if/then. You might as well use switch if that's what you prefer. "Premature optimization is the root of all evil...." ;)
Your answer
Follow this Question
Related Questions
Override/remove an error from console? 1 Answer
Method not found: 'UnityEngine.Application.Loadlevel'? 0 Answers
Why Am I getting MissingMethodException message? 3 Answers
Draw calls on PC and Console? 0 Answers
BCE0044 unexpected char : 'h'. 1 Answer