{"record":{"id":"b1926b68d77daa93","repo":"EllanJiang/GameFramework","slug":"load-asset-callbacks-is-invalid","errorCode":null,"errorMessage":"Load asset callbacks is invalid.","messagePattern":"Load asset callbacks is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.cs","lineNumber":1472,"sourceCode":"\n            return m_ResourceLoader.HasAsset(assetName);\n        }\n\n        /// <summary>\n        /// 异步加载资源。\n        /// </summary>\n        /// <param name=\"assetName\">要加载资源的名称。</param>\n        /// <param name=\"loadAssetCallbacks\">加载资源回调函数集。</param>\n        public void LoadAsset(string assetName, LoadAssetCallbacks loadAssetCallbacks)\n        {\n            if (string.IsNullOrEmpty(assetName))\n            {\n                throw new GameFrameworkException(\"Asset name is invalid.\");\n            }\n\n            if (loadAssetCallbacks == null)\n            {\n                throw new GameFrameworkException(\"Load asset callbacks is invalid.\");\n            }\n\n            m_ResourceLoader.LoadAsset(assetName, null, Constant.DefaultPriority, loadAssetCallbacks, null);\n        }\n\n        /// <summary>\n        /// 异步加载资源。\n        /// </summary>\n        /// <param name=\"assetName\">要加载资源的名称。</param>\n        /// <param name=\"assetType\">要加载资源的类型。</param>\n        /// <param name=\"loadAssetCallbacks\">加载资源回调函数集。</param>\n        public void LoadAsset(string assetName, Type assetType, LoadAssetCallbacks loadAssetCallbacks)\n        {\n            if (string.IsNullOrEmpty(assetName))\n            {\n                throw new GameFrameworkException(\"Asset name is invalid.\");\n            }\n","sourceCodeStart":1454,"sourceCodeEnd":1490,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.cs#L1454-L1490","documentation":"LoadAsset requires a LoadAssetCallbacks instance so the caller can receive success, failure, and dependency-asset callbacks. Passing null would make load results undeliverable, so ResourceManager throws this GameFrameworkException. All LoadAsset overloads ultimately funnel through this check.","triggerScenarios":"Calling LoadAsset(assetName, null) or an overload where the callbacks argument resolves to null — e.g. a cached callbacks object never initialized, or a helper that forwards a null callbacks parameter.","commonSituations":"Wrapping LoadAsset in a utility whose optional callbacks parameter defaults to null then is forwarded; refactoring removed the 'new LoadAssetCallbacks(...)' construction; passing null intending 'fire and forget' (not supported).","solutions":["Always construct and pass LoadAssetCallbacks (at minimum with onLoadAssetFailure set) to LoadAsset.","If you truly need no-op handling, pass a callbacks instance with empty/no-op handlers.","Audit helper methods that forward callbacks and give them a non-null default."],"exampleFix":"// before\nm_ResourceManager.LoadAsset(assetName, null); // throws\n// after\nm_ResourceManager.LoadAsset(assetName, new LoadAssetCallbacks(\n    onSuccess: (assetName, asset, duration) => { /* use asset */ },\n    onFailure: (assetName, status, errMsg) => Debug.LogError(errMsg)));","handlingStrategy":"type-guard","validationCode":"if (loadAssetCallbacks == null) { loadAssetCallbacks = new LoadAssetCallbacks((n,a,d)=>{}, (n,s,m)=>Debug.LogError(m)); }","typeGuard":"static bool HasCallbacks(LoadAssetCallbacks c) => c != null;","tryCatchPattern":"try { rm.LoadAsset(name, callbacks); } catch (GameFrameworkException ex) { Debug.LogError(ex.Message); }","preventionTips":["Never forward optional callbacks parameters as null","Create LoadAssetCallbacks with at least a failure handler","Give wrapper helpers a default non-null callbacks instance"],"tags":["gameframework","load-asset","callbacks","null-argument"],"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"}