{"record":{"id":"5a211214f0efbd28","repo":"EllanJiang/GameFramework","slug":"can-not-find-ui-form-0","errorCode":null,"errorMessage":"Can not find UI form '{0}'.","messagePattern":"Can not find UI form '(.+?)'\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/UI/UIManager.cs","lineNumber":792,"sourceCode":"\n        /// <summary>\n        /// 关闭界面。\n        /// </summary>\n        /// <param name=\"serialId\">要关闭界面的序列编号。</param>\n        /// <param name=\"userData\">用户自定义数据。</param>\n        public void CloseUIForm(int serialId, object userData)\n        {\n            if (IsLoadingUIForm(serialId))\n            {\n                m_UIFormsToReleaseOnLoad.Add(serialId);\n                m_UIFormsBeingLoaded.Remove(serialId);\n                return;\n            }\n\n            IUIForm uiForm = GetUIForm(serialId);\n            if (uiForm == null)\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Can not find UI form '{0}'.\", serialId));\n            }\n\n            CloseUIForm(uiForm, userData);\n        }\n\n        /// <summary>\n        /// 关闭界面。\n        /// </summary>\n        /// <param name=\"uiForm\">要关闭的界面。</param>\n        public void CloseUIForm(IUIForm uiForm)\n        {\n            CloseUIForm(uiForm, null);\n        }\n\n        /// <summary>\n        /// 关闭界面。\n        /// </summary>\n        /// <param name=\"uiForm\">要关闭的界面。</param>","sourceCodeStart":774,"sourceCodeEnd":810,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/UI/UIManager.cs#L774-L810","documentation":"CloseUIForm(int serialId) resolves the serial ID to an open UI form via GetUIForm; when no form with that serial ID exists (never opened, already closed, or loaded from a stale id), the framework throws this formatted GameFrameworkException including the id.","triggerScenarios":"Calling CloseUIForm with a serialId that does not correspond to any currently open UI form — e.g. closing twice, closing a form that failed to load, or using a saved/stale serial id across scenes.","commonSituations":"Double-close on the same event, close-all triggered while a form's open callback had not yet finished, storing serial ids that become invalid after scene switches, or off-by-one around the ++m_Serial id generation.","solutions":["Check existence before closing: if (uiManager.GetUIForm(serialId) != null) uiManager.CloseUIForm(serialId);","Track form validity: set the stored id to 0/invalid after CloseUIForm succeeds to prevent double-close","Use IsAvailableUIFormSerialId / HasUIForm checks if exposed by your framework version","Catch GameFrameworkException around close calls driven by external events"],"exampleFix":"// before\nuiManager.CloseUIForm(m_MenuSerialId); // may already be closed\n// after\nif (uiManager.GetUIForm(m_MenuSerialId) != null)\n{\n    uiManager.CloseUIForm(m_MenuSerialId);\n    m_MenuSerialId = 0;\n}","handlingStrategy":"validation","validationCode":"if (serialId <= 0 || uiManager.GetUIForm(serialId) == null)\n{\n    Log.Warn($\"Skipping CloseUIForm: no open form with id {serialId}\");\n    return;\n}","typeGuard":"bool FormIsOpen(UIManager m, int serialId) => serialId > 0 && m.GetUIForm(serialId) != null;","tryCatchPattern":"try { uiManager.CloseUIForm(serialId); }\ncatch (GameFrameworkException ex) when (ex.Message.Contains(\"Can not find UI form\"))\n{ Log.Warn($\"Stale UI form id {serialId}\"); }","preventionTips":["Invalidate stored serial ids (set to 0) immediately after closing","Guard close-all/close logic against double invocation with a flag","Never persist serial ids across scene changes; re-resolve forms after transitions"],"tags":["ui","entity-not-found","serial-id"],"backgroundTag":"entity-not-found","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}