{"record":{"id":"341267c54254df9d","repo":"EllanJiang/GameFramework","slug":"init-resources-complete-callback-is-invalid","errorCode":null,"errorMessage":"Init resources complete callback is invalid.","messagePattern":"Init resources complete callback is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.cs","lineNumber":1092,"sourceCode":"            }\n\n            if (string.IsNullOrEmpty(m_ReadWritePath))\n            {\n                throw new GameFrameworkException(\"Read-write path is invalid.\");\n            }\n\n            m_ResourceLoader.AddLoadResourceAgentHelper(loadResourceAgentHelper, m_ResourceHelper, m_ReadOnlyPath, m_ReadWritePath, m_DecryptResourceCallback);\n        }\n\n        /// <summary>\n        /// 使用单机模式并初始化资源。\n        /// </summary>\n        /// <param name=\"initResourcesCompleteCallback\">使用单机模式并初始化资源完成时的回调函数。</param>\n        public void InitResources(InitResourcesCompleteCallback initResourcesCompleteCallback)\n        {\n            if (initResourcesCompleteCallback == null)\n            {\n                throw new GameFrameworkException(\"Init resources complete callback is invalid.\");\n            }\n\n            if (m_ResourceMode == ResourceMode.Unspecified)\n            {\n                throw new GameFrameworkException(\"You must set resource mode first.\");\n            }\n\n            if (m_ResourceMode != ResourceMode.Package)\n            {\n                throw new GameFrameworkException(\"You can not use InitResources without package resource mode.\");\n            }\n\n            if (m_ResourceIniter == null)\n            {\n                throw new GameFrameworkException(\"You can not use InitResources at this time.\");\n            }\n\n            m_RefuseSetFlag = true;","sourceCodeStart":1074,"sourceCodeEnd":1110,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.cs#L1074-L1110","documentation":"Thrown by ResourceManager.InitResources when the initResourcesCompleteCallback argument is null. The library requires a callback to deliver the initialization result (success or failure) and refuses to start single-player-mode resource initialization without one.","triggerScenarios":"Calling InitResources(null), or passing a method reference that resolves to null (e.g. an unassigned delegate field).","commonSituations":"Assigning the callback through a serialized UnityEvent or field that was never wired; refactoring removed the handler but not the call.","solutions":["Pass a non-null InitResourcesCompleteCallback lambda or method group, e.g. (success) => { ... }","If the callback comes from a field/event, ensure it is assigned before calling InitResources","Wrap initialization in a check that logs and aborts when the callback is missing"],"exampleFix":"// before\nresourceManager.InitResources(null);\n// after\nresourceManager.InitResources(success =>\n{\n    Debug.Log($\"Init resources {(success ? \"succeeded\" : \"failed\")}\");\n});","handlingStrategy":"validation","validationCode":"if (initCallback == null) throw new InvalidOperationException(\"initResourcesCompleteCallback must not be null\");","typeGuard":"bool HasCallback(InitResourcesCompleteCallback cb) => cb != null;","tryCatchPattern":"try { resourceManager.InitResources(cb); } catch (GameFrameworkException ex) { Debug.LogError($\"InitResources failed: {ex.Message}\"); }","preventionTips":["Always pass an inline lambda or verified method group to InitResources","Avoid nullable delegate fields for callbacks","Handle both success and failure inside the callback"],"tags":["null-argument","resource","gameframework","callback"],"backgroundTag":"null-argument","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"}