BeginScrollView causes stack error
Hello!, I have the following piece of code:
scrollPosition = GUI.BeginScrollView(new Rect(10, Screen.height - 400, 200, 300), scrollPosition, new Rect(0, 0, 200, 300));
GUILayout.TextArea(chat, GUILayout.ExpandHeight(true));
GUILayout.EndScrollView();
Whenever I run the project, I get the following errors over and over again:
InvalidOperationException: Operation is not valid due to the current state of the object
System.Collections.Stack.Pop () (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections/Stack.cs:329)
UnityEngine.GUILayoutUtility.EndLayoutGroup () (at C:/buildslave/unity/build/Runtime/IMGUI/Managed/GUILayoutUtility.cs:279)
UnityEngine.GUILayout.EndScrollView (Boolean handleScrollWheel) (at C:/buildslave/unity/build/Runtime/IMGUI/Managed/GUILayout.cs:427)
UnityEngine.GUILayout.EndScrollView () (at C:/buildslave/unity/build/Runtime/IMGUI/Managed/GUILayout.cs:421)
main.OnGUI () (at Assets/Scripts/main.cs:1111)
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:/buildslave/unity/build/Runtime/IMGUI/Managed/GUILayoutUtility.cs:280)
UnityEngine.GUILayout.EndScrollView (Boolean handleScrollWheel) (at C:/buildslave/unity/build/Runtime/IMGUI/Managed/GUILayout.cs:427)
UnityEngine.GUILayout.EndScrollView () (at C:/buildslave/unity/build/Runtime/IMGUI/Managed/GUILayout.cs:421)
main.OnGUI () (at Assets/Scripts/main.cs:1111)
I have a scroll view in another class and that is working just fine. So my question is, where do these errors come from and how can I fix them?
Answer by Tzeny · Mar 16, 2016 at 07:11 AM
I started the scroll view with GUI and tried to end it with GUILayout. My bad
Your answer
![](https://koobas.hobune.stream/wayback/20220612072024im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A Problem With A Script Of GUI.HorizontalSlider It Do not Move? 0 Answers
GridLayoutGroup issue after loading scene and dynamically adding Instances 1 Answer
Speed up Scroll Rect drag 0 Answers
UGUI is working too slow on iOS builds after update to Unity 5.2.x 1 Answer
I tried to make a Scroll menu with the Scrollrect and now the Camera is permanently zoomed. 1 Answer