"GUI Error: You are pushing more GUIClips than you are popping."

GUI Error:

You are pushing more GUIClips than you are popping.

Make sure they are balanced (type:Layout)

I think it's pointing to this code: (it is slighty modified - the real code is far more complex ;) )

var imageTexture:Texture=null;
var MyLib:MyLibClass=null;
var p:MyPictureObject=null;

function Start(){
    p=MyLib.GetARandomPicture();
}

function OnGUI(){
    if (imageTexture==null){
        var url=p.GetImage();
        if (url!="" && p.IsBusy()==false){
            p.SetBusy(true);
            Debug.Log("getting an image texture",this);
            if (p.GetImageTexture()!=null){
                Debug.Log("getting an image texture from cache",this);
                imageTexture=p.GetImageTexture();
            } else {
                Debug.Log("getting an image texture from web: "+url,this);
                var www=new WWW(url);
                yield www;
                p.SetimageTexture(www.texture);
                imageTexture=www.texture;
            }   
            p.SetBusy(false);
        }
    }
    GUILayout.Box(Rect(0,0,100,100), imageTexture);
    if (GUILayout.Button("a different image please")){
        p=MyLib.GetARandomPicture();
    }
}

I use p.SetBusy() and p.IsBusy() to avoid multiple requests for one image.

I use p.GetImageTexture() and p.SetImageTexture() for caching request responses.

So If I use caching and avoid asyncronous problems - why do I get something like a stackoverflow on the request buffer?

Regarding GUIClips: The case where I remember getting that error was when I had a GUILayout.BeginArea that didn't have a corresponding EndArea (or in general, a GUILayout.Begin[Something] that didn't have the corresponding End[Something] call). Have you checked that is not the case elsewhere in your code?

What do you mean by "something like a stackoverflow"? What does p.GetImage() do ?

Also, notice that if what you want to do is to have the image change every time you press the button, the code will likely not work anyway, as you only obtain a new image if the imageTexture is null, which it won't be after the first time you assign it.

Problem solved:

Don't use yield in OnGUI() between GUILayout.BeginArea() and GUILayout.EndArea()

I usually get this if I forget to close the ScrollView

A common problem is placing logic that changes the GUI layout within the OnGUI() function and this is corrupting the repaint and layout synch.

Changing the code to place anything that would affect the GUI in Update() can fix the problem in some instances.