- Home /
InvalidOperationException: Operation is not valid due to the current state of the object System.Collections.Stack.Peek ()
I have a custom component which i use in Editor GUI.
It works well in case if I don't use any layout blocs like ScrollView, HorizontalView and so on, but if I use on of them i'm getting following exception
System.Collections.Stack.Peek () (at /Applications/buildAgent/work/3df08680c6f85295/mcs/class/corlib/System.Collections/Stack.cs:321) UnityEngine.GUILayoutUtility.EndLayoutGroup () UnityEngine.GUILayout.EndHorizontal () UnityEditor.EditorGUILayout.EndHorizontal () UFTTestAtlasEntry.showAllSprites () (at Assets/Tests/Editor/UFTTestAtlasEntry.cs:37) UFTTestAtlasEntry.OnGUI () (at Assets/Tests/Editor/UFTTestAtlasEntry.cs:27) System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/3df08680c6f85295/mcs/class/corlib/System.Reflection/MonoMethod.cs:222) here is a part of code where i'm getting this error void OnGUI () {InvalidOperationException: Operation is not valid due to the current state of the object
showAllSprites ();
}
void showAllSprites () { EditorGUILayout.BeginHorizontal();
e1 = UFTEditorGUILayout.atlasEntryMetadata(atlasMetadata,e1, GetInstanceID());
e2 = UFTEditorGUILayout.atlasEntryMetadata(atlasMetadata,e2, GetInstanceID());
EditorGUILayout.EndHorizontal(); } I saw this topic http://answers.unity3d.com/questions/31006/problem-with-scrollview.html but it doesn't work for me. [here is][1] a source code of the whole project. and [this is][2] UFTEditorGUILayout class which render my own object update 1 i found problem part of code Somwhere in UFTEditorGUILayout.atlasEntryMetadata there is initialisation of additional window. public static UFTSpriteChooseWindow Initialize(UFTAtlasMetadata atlasMetadata, UFTAtlasEntryMetadata atlasEntryMetadata, Vector2 parentWindowPosition, string parentControlKey){ UFTSpriteChooseWindow window=ScriptableObject.CreateInstance(); window.atlasMetadata=atlasMetadata; window.atlasEntryMetadata=atlasEntryMetadata; window.parentControlKey=parentControlKey; Rect position=new Rect(Event.current.mousePosition.x + parentWindowPosition.x -30, parentWindowPosition.y-200, 250, 50); window.position=position; window.ShowAsDropDown(window.position,new Vector2(120,500)); //here is i'm getting System.Collections.Stack.Peek exception //window.Show();// It works well return window; } and window.Show() works well, without any exception, but window.ShowAsDropDown(...) show this exception. I don't know how to fix it with DropDown, but what i need is this ![alt text][3] it's just a custom combobox. [1]: http://git.nicloay.com/spritebutton/src [2]: http://git.nicloay.com/spritebutton/src/8cf68d9a20dd5fe455eeb37e7206c668d9db2f06/Assets/UFTSpriteMenuButton/Editor/UFTEditorGUILayout.cs?at=master [3]: /storage/temp/8704-screen+shot+2013-03-08+at+7.38.42+pm.png
Answer by leonard384 · Jul 30, 2014 at 11:29 AM
Same error for me, but i try implement my own CustomEditor. After wasting a lot time in google and finding nothing, I begin playing around with this error, and this how i did fix it in my own code...
[CustomEditor(typeof(SomeClass))]
class SomeClassCustomEditor : UnityEditor.Editor
{
public override void OnInspectorGUI()
{
var myTarget = (SomeClass)target;
// call it with EditorApplication.delayCall +=
if (GUILayout.Button("Some Unsafe Action"))
EditorApplication.delayCall += myTarget.SomeUnsafeAction;
// call it directly
if (GUILayout.Button("Some Safe Action"))
myTarget.SomeSafeAction();
}
}
------------------------------------------------
class SomeClass : MonoBehaviour // of myTarget
{
#if UNITY_EDITOR
public void SomeUnsafeAction()
{
...some code, leads to triggering that ERROR
}
public void SomeSafeAction()
{
...some safe code, NOT triggering that ERROR
}
#endif
}
我用这个方法成功了,非常感谢!! if (GUILayout.Button("Some Unsafe Action")) EditorApplication.delayCall += myTarget.SomeUnsafeAction;
Tk you very much!!
Your answer
Follow this Question
Related Questions
Player controls for scrolling horizontally/vertically? 0 Answers
Add EditorUI elements when a button is pressed 0 Answers
EditorGUI like light explorer window 1 Answer
ScrollView disappears shortly after starting the game (Android) 1 Answer
Editor -> Popupwindow -> OnLostFocus -> Close() -> Get Windowlayouts error, wait what? 0 Answers