为啥尝试在编辑器窗口中进行垂直滚动时出现异常 InvalidOperationException: Stack empty.?
Posted
技术标签:
【中文标题】为啥尝试在编辑器窗口中进行垂直滚动时出现异常 InvalidOperationException: Stack empty.?【英文标题】:Why when trying to make vertical scroll in editorwindow I'm getting exception InvalidOperationException: Stack empty.?为什么尝试在编辑器窗口中进行垂直滚动时出现异常 InvalidOperationException: Stack empty.? 【发布时间】:2019-10-02 18:45:49 【问题描述】:我要做的是在将编辑器窗口扩展到底部时添加自动垂直滚动:
例如,如果在屏幕截图中这是原始编辑器窗口大小:
例如,当单击“对话”并将其折叠时,我想使用垂直滚动来制作它:
我可以用鼠标继续向下拉伸窗口,但在这种情况下我想使用滚动:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
public class ConversationsEditorWindow : EditorWindow
[MenuItem("Window/Editor Window Test")]
static void Init()
// Get existing open window or if none, make a new one:
ConversationsEditorWindow window = (ConversationsEditorWindow)EditorWindow.GetWindow(typeof(ConversationsEditorWindow));
void OnGUI()
GameObject sel = Selection.activeGameObject;
ConversationTrigger targetComp = sel.GetComponent<ConversationTrigger>();
if (targetComp != null)
EditorGUILayout.BeginVertical();
var editor = Editor.CreateEditor(targetComp);
var tar = editor.targets;
editor.OnInspectorGUI();
EditorGUILayout.EndScrollView();
EditorGUILayout.EndVertical();
异常消息有点长: 例外情况在第 27 行:
EditorGUILayout.EndScrollView();
InvalidOperationException:堆栈为空。 System.Collections.Stack.Peek () (at :0) UnityEngine.GUI.EndScrollView (System.Boolean handleScrollWheel) (在 C:/buildslave/unity/build/Modules/IMGUI/GUI.cs:1481) UnityEngine.GUILayout.EndScrollView (System.Boolean handleScrollWheel) (在 C:/buildslave/unity/build/Modules/IMGUI/GUILayout.cs:387) unityEditor.EditorGUILayout.EndScrollView() (在 C:/buildslave/unity/build/Editor/Mono/EditorGUI.cs:9203) ConversationsEditorWindow.OnGUI () (在 Assets/Editor/ConversationsEditorWindow.cs:27) System.Reflection.MonoMethod.Invoke(System.Object obj,System.Reflection.BindingFlags invokeAttr,System.Reflection.Binder binder,System.Object[] 参数,System.Globalization.CultureInfo 文化)(在:0) Rethrow as TargetInvocationException:调用的目标已引发异常。 System.Reflection.MonoMethod.Invoke(System.Object obj,System.Reflection.BindingFlags invokeAttr,System.Reflection.Binder binder,System.Object[] 参数,System.Globalization.CultureInfo 文化)(在:0) System.Reflection.MethodBase.Invoke(System.Object obj,System.Object[] 参数)(在:0) UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (在 C:/buildslave/unity/build/Editor/Mono/HostView.cs:342) UnityEditor.HostView.Invoke (System.String methodName) (在 C:/buildslave/unity/build/Editor/Mono/HostView.cs:336) UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (在 C:/buildslave/unity/build/Editor/Mono/HostView.cs:310) UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect, System.Boolean customBorder, System.Boolean floatingWindow, System.Boolean isBottomTab) (在 C:/buildslave/unity/build/Editor/Mono/GUI/DockArea. cs:361) unityEditor.DockArea.OldOnGUI () (在 C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:320) UnityEngine.Experimental.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout) (在 C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:244 ) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
【问题讨论】:
【参考方案1】:堆栈空消息提供了一个线索 - 你正在调用:EditorGUILayout.EndScrollView(); (试图从 gui 堆栈中弹出)而不事先调用 BeginScrollView()。
【讨论】:
以上是关于为啥尝试在编辑器窗口中进行垂直滚动时出现异常 InvalidOperationException: Stack empty.?的主要内容,如果未能解决你的问题,请参考以下文章
为啥在 glfw 窗口上没有使用 opengl 显示位图图像?在 C++ 中读取位图图像文件时出现问题
为啥在尝试将 Hibernate Spatial 用于 Spring Boot 项目时出现此错误?实例化异常