{"record":{"id":"9f6746d12375f2dc","repo":"Unity-Technologies/UnityCsReference","slug":"cannot-create-more-than-one-main-window","errorCode":null,"errorMessage":"Cannot create more than one main window.","messagePattern":"Cannot create more than one main window\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/ContainerWindow.cs","lineNumber":149,"sourceCode":"\n        internal bool isPopup => IsPopup((ShowMode)m_ShowMode);\n\n        internal void ShowPopup()\n        {\n            ShowPopupWithMode(ShowMode.PopupMenu, true);\n        }\n\n        internal void ShowTooltip()\n        {\n            ShowPopupWithMode(ShowMode.Tooltip, false);\n        }\n\n        internal void ShowPopupWithMode(ShowMode mode, bool giveFocus)\n        {\n            try\n            {\n                if (mode == ShowMode.MainWindow)\n                    throw new ArgumentException(\"Cannot create more than one main window.\");\n\n                m_ShowMode = (int)mode;\n                Internal_Show(m_PixelRect, m_ShowMode, m_MinSize, m_MaxSize);\n                if (m_RootView)\n                    m_RootView.SetWindowRecurse(this);\n                Internal_SetTitle(m_Title);\n                Save();\n\n                // System windows that come from the OS (like a context menu from search) need theming\n                SetBackgroundColor(skinBackgroundColor);\n\n                //  only set focus if mode is a popupMenu.\n                Internal_BringLiveAfterCreation(true, giveFocus, false);\n\n                // Fit window to screen - needs to be done after bringing the window live\n                position = FitRectToScreen(m_PixelRect, m_PixelRect.center, true, this);\n                rootView.position = new Rect(0, 0, GUIUtility.RoundToPixelGrid(m_PixelRect.width), GUIUtility.RoundToPixelGrid(m_PixelRect.height));\n                rootView.Reflow();","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/ContainerWindow.cs#L131-L167","documentation":"ArgumentException thrown by ContainerWindow.ShowPopupWithMode when the requested mode is ShowMode.MainWindow. Popups (tooltips, context menus) must not be created as the main window; the main window is a singleton created through the dedicated path, so ShowPopupWithMode explicitly refuses MainWindow.","triggerScenarios":"Calling ShowPopupWithMode(ShowMode.MainWindow, giveFocus) directly. This is almost always a programming error — passing the wrong ShowMode enum value into a popup-creation routine.","commonSituations":"Miscopying a ShowMode argument; generic window-show helpers that forward an arbitrary mode into ShowPopupWithMode without filtering MainWindow.","solutions":["Do not pass ShowMode.MainWindow to ShowPopupWithMode; use the appropriate popup/aux mode.","Guard the mode argument and route MainWindow through the correct creation path (Show with ShowMode.MainWindow).","Validate the mode is a popup-class mode before calling."],"exampleFix":"// before\nwindow.ShowPopupWithMode(ShowMode.MainWindow, true);\n\n// after\nwindow.ShowPopupWithMode(ShowMode.PopupMenu, true);","handlingStrategy":"validation","validationCode":"if (mode == ShowMode.MainWindow) throw new InvalidOperationException(\"Use Show for the main window, not ShowPopupWithMode.\");\nwindow.ShowPopupWithMode(mode, giveFocus);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass ShowMode.MainWindow into popup helpers.","Route main-window creation through Show.","Validate mode is a popup-class mode first."],"tags":["unity-editor","container-window","argument-validation","show-mode","window-creation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}