Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by nicloay · Mar 08, 2013 at 01:32 PM · guieditorscrollview

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

InvalidOperationException: Operation is not valid due to the current state of the object

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 () {
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
screen shot 2013-03-08 at 7.38.42 pm.png (56.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
7

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
 }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Roc · Mar 19, 2016 at 03:28 AM 0
Share

我用这个方法成功了,非常感谢!! if (GUILayout.Button("Some Unsafe Action")) EditorApplication.delayCall += myTarget.SomeUnsafeAction;

Tk you very much!!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges