{"record":{"id":"b0c13004717538b2","repo":"EllanJiang/GameFramework","slug":"apply-resources-complete-callback-is-invalid","errorCode":null,"errorMessage":"Apply resources complete callback is invalid.","messagePattern":"Apply resources complete callback is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.cs","lineNumber":1261,"sourceCode":"        /// 使用可更新模式并应用资源包资源。\n        /// </summary>\n        /// <param name=\"resourcePackPath\">要应用的资源包路径。</param>\n        /// <param name=\"applyResourcesCompleteCallback\">使用可更新模式并应用资源包资源完成时的回调函数。</param>\n        public void ApplyResources(string resourcePackPath, ApplyResourcesCompleteCallback applyResourcesCompleteCallback)\n        {\n            if (string.IsNullOrEmpty(resourcePackPath))\n            {\n                throw new GameFrameworkException(\"Resource pack path is invalid.\");\n            }\n\n            if (!File.Exists(resourcePackPath))\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Resource pack '{0}' is not exist.\", resourcePackPath));\n            }\n\n            if (applyResourcesCompleteCallback == null)\n            {\n                throw new GameFrameworkException(\"Apply 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.Updatable && m_ResourceMode != ResourceMode.UpdatableWhilePlaying)\n            {\n                throw new GameFrameworkException(\"You can not use ApplyResources without updatable resource mode.\");\n            }\n\n            if (m_ResourceUpdater == null)\n            {\n                throw new GameFrameworkException(\"You can not use ApplyResources at this time.\");\n            }\n\n            m_ApplyResourcesCompleteCallback = applyResourcesCompleteCallback;","sourceCodeStart":1243,"sourceCodeEnd":1279,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.cs#L1243-L1279","documentation":"This GameFrameworkException is thrown by ResourceManager.ApplyResources when the caller passes a null applyResourcesCompleteCallback. The resource manager refuses to start applying a resource pack without a completion callback because it must be able to notify the caller when the apply operation finishes. It is a fail-fast argument validation guard.","triggerScenarios":"Calling ResourceManager.ApplyResources(resourcePackPath, null), or passing a callback variable that has not been initialized (e.g. a field left null before the call).","commonSituations":"Callback wiring removed during refactors; conditional code paths where the callback is assigned only in some branches; calling ApplyResources from generated or wrapped code that forwards a null delegate.","solutions":["Pass a non-null ApplyResourcesCompleteCallback delegate as the second argument to ApplyResources.","If the callback is a stored field, initialize it before calling ApplyResources (or assert it is not null first).","Check the call site for refactors that accidentally dropped the callback argument."],"exampleFix":"// before\nresourceManager.ApplyResources(packPath, null);\n// after\nresourceManager.ApplyResources(packPath, (success) => {\n    UnityEngine.Debug.LogFormat(\"Apply resources {0}.\", success ? \"complete\" : \"failed\");\n});","handlingStrategy":"validation","validationCode":"if (callback == null) throw new ArgumentNullException(nameof(callback));\nresourceManager.ApplyResources(packPath, callback);","typeGuard":"bool HasCallback(ApplyResourcesCompleteCallback cb) => cb != null;","tryCatchPattern":"try { resourceManager.ApplyResources(packPath, callback); }\ncatch (GameFrameworkException ex) { UnityEngine.Debug.LogError($\"ApplyResources failed: {ex.Message}\"); }","preventionTips":["Always supply a completion callback when calling ApplyResources.","Initialize callback fields at declaration or in init, not conditionally.","Assert non-null arguments in wrappers around resource APIs."],"tags":["csharp","gameframework","argument-validation","null-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-15T23:17:13.987Z"}