- Home /
Problem with ScrollView
I am getting the error "Operation is not valid due to the current state of the object System.Collections.Stack.Peek ()" while building and animating a GUI accordion for smooth moviment using scrollview. What could be happening?
Thanks in advance.
Here is the Code:
void OnGUI() { GUISkin skin = GUI.skin; GUI.skin = sknScrollbar; if (this.Display) { GUILayout.BeginArea(this.rtComponentPosition); vtScroll = GUILayout.BeginScrollView(vtScroll, GUILayout.Height(Screen.height - rtComponentPosition.yMin), GUILayout.Width(this.rtComponentPosition.width)); ListChilds(root.childs); GUILayout.EndScrollView(); GUILayout.EndArea(); } GUI.skin = skin; }
void ListChilds(IList<Item> childs) { foreach (Item item in childs) { item.scrollHeight = getScrollSize(item); if (item.Nome == "PINTAR" || item.Nome == "DECORAR") { accordionSize = 29; } else accordionSize = 25;
if (item.Nome == currentItem)
{
GUILayout.BeginScrollView(new Vector2(), GUILayout.Height(accordionHeight));
if (item.isOpened && !item.closening && accordionHeight < accordionSize * (1 + item.childs.Count))
{
accordionHeight += 2;
}
if (item.closening == true && accordionHeight > 29)
{
accordionHeight -= 2;
}
if (item.closening == true && accordionHeight <= 29)
{
item.isOpened = false;
item.closening = false;
}
}
if (GUILayout.Button(item.Nome, item.style))
{
if (item.isOpened == false)
{
item.isOpened = true;
}
else
{
item.closening = true;
}
item.SetClick();
}
if ((item.childs != null) && (item.isOpened))
ListChilds(item.childs);
if (item.Nome == currentItem)
{
GUILayout.EndScrollView();
}
}
Answer by Antares19 · Jan 14, 2013 at 07:05 PM
Julian, your hint helped alot! Thank you.
I've encountered same nasty bug with "GUILayout.BeginHorizontal". Spend few hours in debugging before figured out the source of the problem. After finding your answer here, I ended up with code like this:
GUILayout.BeginHorizontal();
bool isHorizontalBlockActive = true;
if(GUILayout.Button("Start complex process"){
MyComplexProcess();
isHorizontalBlockActive = false;
}
// ...more buttons here
if(isHorizontalBlockActive)
GUILayout.EndHorizontal();
Looks ugly, but works fine :)
heh.. it's good when you have all your code in one class. And it doesn't work for my custom component.
void OnGUI () {
showAllSprites ();
}
void showAllSprites ()
{
EditorGUILayout.BeginHorizontal();
bool horizontalActive=true;
e1 = UFTEditorGUILayout.showAtlasEntryGUI(atlas$$anonymous$$etadata,e1, GetInstanceID());
e2 = UFTEditorGUILayout.showAtlasEntryGUI(atlas$$anonymous$$etadata,e2, GetInstanceID());
if (horizontalActive)
EditorGUILayout.EndHorizontal();
}
here is my code, and anyway i'm getting this error, on if(horizontalActive) block
You are never setting horizontalActive to false anywhere in your code. In the code you posted the two lines you added don't actually change anything.
mikeschuld, UFTEditorGUILayout.showAtlasEntryGUI has a lot of calls of different GUILayout methods inside. Sorry, but i don't remember how did i solve my problem.
Answer by Julian Witte · Oct 22, 2010 at 05:47 PM
Well, I found out what was happening. the "item.SetClick();" changes the currentItem string, and doing that, the condition is true for the EndScrollView() before the BegingScrollView exists, as it tries to End something that doesn't yet exists, the error is returned.
I fixed the problem adding a bool to the End condition that is false on SetClick() and only is only set true after BeginScrollView().
Hopes it helps anyone someday...
Your answer
