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 MapuHoB · Dec 11, 2014 at 12:41 PM · c#editorexception

InvalidOperationException: Operation is not valid due to the current state of the object System.Collections.Stack.Peek ()

 InvalidOperationException: Operation is not valid due to the current state of the object
 System.Collections.Stack.Peek () (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections/Stack.cs:321)
 UnityEngine.GUILayoutUtility.EndLayoutGroup () (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/GUILayoutUtility.cs:223)
 UnityEngine.GUILayout.EndHorizontal () (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/GUILayout.cs:244)
 UnityEditor.BuildPlayerWindow.ActiveBuildTargetsGUI () (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/BuildPlayerWindow.cs:1079)
 UnityEditor.BuildPlayerWindow.OnGUI () (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/BuildPlayerWindow.cs:1171)
 System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
 Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
 System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
 System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
 UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/GUI/DockArea.cs:244)
 UnityEditor.HostView.Invoke (System.String methodName) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/GUI/DockArea.cs:237)
 UnityEditor.HostView.OnGUI () (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/GUI/DockArea.cs:129)

This happens when I switch platforms and I've no idea what is going on

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

3 Replies

· Add your reply
  • Sort: 
avatar image
14
Best Answer

Answer by Baste · Dec 11, 2014 at 01:40 PM

When you switch platforms as in when you open the build menu and click "Switch Platform"?

And Unity crashes? Every time?

So the error seems to be related to the GUI layout. Some stack implementation used breaks hard for some reason. Reading through the source for Stack.cs in the mono Github*, this happens a lot:

 if (current == -1) {
     throw new InvalidOperationException();
 }

Where current is the index of the current element. What's happening is that the stack is empty, and the current element is set to be the element at index (size - 1), where size is the size of the stack.

How to fix this? I'd try to set the layout to the default layout (upper right corner), and restart Unity.

*Note that Unity's version of Mono is not the one on GitHub - indeed the line you're getting in the stack trace could not throw an exception - but it's probably not changed that much.

Comment
Add comment · Show 4 · 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 MapuHoB · Dec 11, 2014 at 02:39 PM -1
Share

Thanks it worked! :)

avatar image petey · Jan 12, 2015 at 10:32 AM -1
Share

Holy Crap! Thanks for posting that! I would have never thought loading the default layout would solve a problem like this :)

avatar image aliaramli · Apr 20, 2015 at 06:34 AM -1
Share

Hi, i tried on switching platform. it works charmly. thanks!

avatar image DDeathlonger · Nov 20, 2017 at 06:22 AM 0
Share

What? Switching to default layout doesn't change anything.. .

avatar image
10

Answer by Robotron18 · Jul 15, 2015 at 08:08 AM

If you do own tools in the Editor(Unity5), you can use this callback for correct run any methods without exeptions. It's very comfortably. Like this

 void OnGUI()
 {
   EditorGUILayout.BeginHorizontal();
   if (GUILayout.Button("Build all"))
   {
     EditorApplication.delayCall += BuildAssetsBundles; 
     Close();
   }
   EditorGUILayout.EndHorizontal();
 }
 
 protected virtual void BuildAssetsBundles()
 {
   BuildPipeline.BuildAssetBundles("AssetsBundles");
 }


Comment
Add comment · Show 4 · 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 chasepettit · Jan 05, 2017 at 11:32 PM 1
Share

Thanks. This is definitely the correct way to avoid this issue. Avoids having to do the hacks that most people seem to suggest on here.

avatar image billclock · Dec 01, 2017 at 07:07 AM 0
Share

This is the right answer!!! Thank you!

avatar image Nargess · Jan 25, 2018 at 05:02 AM 0
Share

Thanks for this solution. In which file should we add the above code? I cannot locate GUILayout.cs, if that is the one. Thanks for your help and time in advance.

avatar image AutoFire-II Nargess · May 30, 2018 at 02:58 AM 0
Share

I know this is old, but... Ins$$anonymous$$d of calling the function that's causing the error (BuildAssetsBundles, in this case), you have to add it to the EditorApplication.delayCall delegate. Unfortunately, you may need to write your function in a round-about way, because you cannot receive any return values from functions called this way.

avatar image
0

Answer by warren- · Feb 10, 2017 at 07:29 AM

I had this error pop up when I had an EditorGUILayout.EndHorizontal(); that didn't have a EditorGUILayout.BeginHorizontal();

look for a mismatch for that call.

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 WashingMachine · Nov 12, 2018 at 10:05 AM 0
Share

This did it for me, overlooked an extra EndScrollview() that wasn't supposed to be there. Thanks

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

36 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Initialising List array for use in a custom Editor 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to Save an multidimensional array trough editor script 1 Answer

Create a Component Script for Editor Only 1 Answer


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