{"record":{"id":"df872ae9c6184dca","repo":"EllanJiang/GameFramework","slug":"resource-loader-is-invalid-resourcemanager-resourceloader","errorCode":null,"errorMessage":"Resource loader is invalid.","messagePattern":"Resource loader is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"critical","filePath":"GameFramework/Resource/ResourceManager.ResourceLoader.LoadResourceAgent.cs","lineNumber":59,"sourceCode":"                /// <param name=\"resourceLoader\">加载资源器。</param>\n                /// <param name=\"readOnlyPath\">资源只读区路径。</param>\n                /// <param name=\"readWritePath\">资源读写区路径。</param>\n                /// <param name=\"decryptResourceCallback\">解密资源回调函数。</param>\n                public LoadResourceAgent(ILoadResourceAgentHelper loadResourceAgentHelper, IResourceHelper resourceHelper, ResourceLoader resourceLoader, string readOnlyPath, string readWritePath, DecryptResourceCallback decryptResourceCallback)\n                {\n                    if (loadResourceAgentHelper == null)\n                    {\n                        throw new GameFrameworkException(\"Load resource agent helper is invalid.\");\n                    }\n\n                    if (resourceHelper == null)\n                    {\n                        throw new GameFrameworkException(\"Resource helper is invalid.\");\n                    }\n\n                    if (resourceLoader == null)\n                    {\n                        throw new GameFrameworkException(\"Resource loader is invalid.\");\n                    }\n\n                    if (decryptResourceCallback == null)\n                    {\n                        throw new GameFrameworkException(\"Decrypt resource callback is invalid.\");\n                    }\n\n                    m_Helper = loadResourceAgentHelper;\n                    m_ResourceHelper = resourceHelper;\n                    m_ResourceLoader = resourceLoader;\n                    m_ReadOnlyPath = readOnlyPath;\n                    m_ReadWritePath = readWritePath;\n                    m_DecryptResourceCallback = decryptResourceCallback;\n                    m_Task = null;\n                }\n\n                public ILoadResourceAgentHelper Helper\n                {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.ResourceLoader.LoadResourceAgent.cs#L41-L77","documentation":"LoadResourceAgent stores a back-reference to its owning ResourceLoader, which coordinates task queues and dependency maps (m_AssetToResourceMap, m_ResourceDependencyCount). A null resourceLoader would break all task bookkeeping, so the constructor rejects it.","triggerScenarios":"Constructing LoadResourceAgent with null resourceLoader — e.g. manually creating agents outside ResourceLoader, or a broken loader reference in custom resource-agent instantiation code.","commonSituations":"Custom resource agent pools that create agents without passing the loader; refactoring ResourceLoader construction so agents are built before the loader instance exists.","solutions":["Always create agents via ResourceLoader's own agent-creation path so the loader reference is passed automatically.","If creating LoadResourceAgent manually, pass the live ResourceLoader instance, not null.","Check that the loader field is assigned before spawning resource agents in custom code.","Add a null check/assert in custom agent factory code."],"exampleFix":"// before\nvar agent = new LoadResourceAgent(helper, resourceHelper, null, readOnlyPath, readWritePath, callback);\n// after\nvar agent = new LoadResourceAgent(helper, resourceHelper, this, readOnlyPath, readWritePath, callback);","handlingStrategy":"validation","validationCode":"if (resourceLoader == null)\n    throw new ArgumentNullException(nameof(resourceLoader));\n// before manual agent creation: Debug.Assert(loader != null, \"ResourceLoader must exist\");","typeGuard":"bool IsValidLoader(ResourceLoader l) => l != null;","tryCatchPattern":"try\n{\n    resourceComponent.LoadAsset(assetName, assetType, callback);\n}\ncatch (GameFrameworkException ex)\n{\n    Debug.LogError($\"Resource loader not initialized: {ex.Message}\");\n}","preventionTips":["Create LoadResourceAgents only via ResourceLoader's own paths.","Initialize ResourceLoader before spawning agents.","Avoid constructing resource internals directly; use ResourceComponent APIs.","Assert non-null loader in custom agent factories."],"tags":["gameframework","unity","null-argument","resource-loading","initialization"],"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"}