EllanJiang/GameFramework · critical · GameFrameworkException
Resource loader is invalid.
Error message
Resource loader is invalid.
What it means
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.
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.
Example fix
// before var agent = new LoadResourceAgent(helper, resourceHelper, null, readOnlyPath, readWritePath, callback); // after var agent = new LoadResourceAgent(helper, resourceHelper, this, readOnlyPath, readWritePath, callback);
Defensive patterns
Strategy: validation
Validate before calling
if (resourceLoader == null)
throw new ArgumentNullException(nameof(resourceLoader));
// before manual agent creation: Debug.Assert(loader != null, "ResourceLoader must exist"); Type guard
bool IsValidLoader(ResourceLoader l) => l != null;
Try / catch
try
{
resourceComponent.LoadAsset(assetName, assetType, callback);
}
catch (GameFrameworkException ex)
{
Debug.LogError($"Resource loader not initialized: {ex.Message}");
} Prevention
- 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.
When it happens
Trigger: Constructing LoadResourceAgent with null resourceLoader — e.g. manually creating agents outside ResourceLoader, or a broken loader reference in custom resource-agent instantiation code.
Common situations: Custom resource agent pools that create agents without passing the loader; refactoring ResourceLoader construction so agents are built before the loader instance exists.
Related errors
- Load resource agent helper is invalid.
- Resource helper is invalid.
- Decrypt resource callback is invalid.
- Task is invalid.
- Resource manager is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/df872ae9c6184dca.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Resource/ResourceManager.ResourceLoader.LoadResourceAgent.cs:59
/// <param name="resourceLoader">加载资源器。</param>
/// <param name="readOnlyPath">资源只读区路径。</param>
/// <param name="readWritePath">资源读写区路径。</param>
/// <param name="decryptResourceCallback">解密资源回调函数。</param>
public LoadResourceAgent(ILoadResourceAgentHelper loadResourceAgentHelper, IResourceHelper resourceHelper, ResourceLoader resourceLoader, string readOnlyPath, string readWritePath, DecryptResourceCallback decryptResourceCallback)
{
if (loadResourceAgentHelper == null)
{
throw new GameFrameworkException("Load resource agent helper is invalid.");
}
if (resourceHelper == null)
{
throw new GameFrameworkException("Resource helper is invalid.");
}
if (resourceLoader == null)
{
throw new GameFrameworkException("Resource loader is invalid.");
}
if (decryptResourceCallback == null)
{
throw new GameFrameworkException("Decrypt resource callback is invalid.");
}
m_Helper = loadResourceAgentHelper;
m_ResourceHelper = resourceHelper;
m_ResourceLoader = resourceLoader;
m_ReadOnlyPath = readOnlyPath;
m_ReadWritePath = readWritePath;
m_DecryptResourceCallback = decryptResourceCallback;
m_Task = null;
}
public ILoadResourceAgentHelper Helper
{View on GitHub (pinned to d0c010b051)