- Home /
GUI.Window error. InvalidOperationException: Hashtable.Enumerator: snapshot out of sync.
I wanna to draw a menu. and here is the code, but i come across a problem when i hit Play,and i find the error is caused by this line of code below:GUI.Window(GlobalGUIWindowId._WND2_YXY..... ,and the error in the console window says:
InvalidOperationException: Hashtable.Enumerator: snapshot out of sync. System.Collections.Hashtable+Enumerator.FailFast () System.Collections.Hashtable+Enumerator.MoveNext () UnityEngine.GUI.EndWindows (UnityEngine.IDList idlist) (at C:/BuildAgent/work/f724c1acfee760b6/Runtime/ExportGenerated/Editor/GUI.cs:1225) UnityEngine.GUIUtility.EndGUI (Int32 doLayout, Int32 doWindows, UnityEngine.IDList idlist) (at C:/BuildAgent/work/f724c1acfee760b6/Runtime/ExportGenerated/Editor/GUIUtility.cs:359)
I have no idea how to debug it, may you help me. Thank you very much!
void OnGUI() { // _rectMainMenu = new Rect(_menuPos.x, _menuPos.y, Screen.width - _menuPos.x, _mainMenuHeight); _rectMainMenu = GUI.Window(GlobalGUIWindowId._WND1_YXY, _rectMainMenu, MenuMainWindow, "", _mainMenuBackStyle); } void MenuMainWindow(int windowId) { int nNumPopupMenus = _popupMenus.Count; float width = 0f; float x = 0f; for (int i = 0; i < nNumPopupMenus; i++) { PopupMenu popItem = (PopupMenu)_popupMenus[i]; popItem.SetStyles(_mainMenuBackStyle, _menuItemStyle, _menuDisableStyle); width = GUILayoutUtility.GetRect(new GUIContent(popItem.Text), _popupMenuStyle).width + _spaceBetweenMenuItems; print("text, width:" + popItem.Text + ", " + width.ToString()); Rect rectCur = new Rect(x, 0, width, _popupMenuHeight); popItem.DrawPopupMenu(rectCur, _popupMenuStyle); x += width; } }
public void DrawPopupMenu(Rect rect, GUIStyle popupMenuStyle) { GUIContent guiContent = new GUIContent(_text); GUI.Label(rect, guiContent, popupMenuStyle); // // _menuItemMaxWidth = 100;//not complete
rectMax = new Rect(10, 10, _menuItemMaxWidth, 10);
***GUI.Window(GlobalGUIWindowId._WND2_YXY, rectMax, DrawItsMenuItems, "", _mainMenuStyle);//***
}
private void DrawItsMenuItems(int windowId) { // //int nNumMenuItems = _menuItems.Count; //float y = 0; //for (int i = 0; i < nNumMenuItems; i++) //{ // MenuItem item = (MenuItem)_menuItems[i]; // if (item.Show) // { // // // // // _menuItemHeight = 18; // Rect rectMenuItem = new Rect(0, y, _menuItemMaxWidth, _menuItemHeight); // //item.DrawMenuItem(rectMenuItem, _menuItemStyle, _disableMenuItemStyle); // } // y += _menuItemHeight; //} }