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

If I do this I get the error in the title (twice!):

Handles.BeginGUI(new Rect(Screen.width - 100, Screen.height - 80, 90,50));

GUILayout.Label(mousePos.ToString());

Handles.EndGUI();

However if I do this, I get no error:

Handles.BeginGUI();

GUILayout.Label(mousePos.ToString());

Handles.EndGUI();

Why is this happening and how do I fix the errors?

Thanks

Quite easy workaround is to use GUILayout.BeginArea().

Handles.BeginGUI();
GUILayout.BeginArea(new Rect(Screen.width - 100, Screen.height - 80, 90,50));

GUILayout.Label(mousePos.ToString());

GUILayout.EndArea();
Handles.EndGUI();

I just had this error myself and the answer from hardwire fixes the problem. Personally, though, I wanted to find out why and answer OP’s question.

Simple answer. Handles.BeginGUI(Rect rect) calls GUILayout.BeginArea(Rect rect) underneath. But, Handles.EndGUI() does not call GUILayout.EndArea(). Therefore, the begins and ends don’t actually match even when they do in your own code.