EllanJiang/GameFramework · error · GameFrameworkException
Task is invalid.
Error message
Task is invalid.
What it means
LoadResourceAgent.Start receives the LoadResourceTask to execute and immediately validates it. A null task means there is nothing to process and the agent's state (m_Task, StartTime, ResourceInfo) could not be set up, so GameFramework throws.
Solutions
- Never call Start directly with null; let ResourceLoader's task loop manage tasks and check TryDequeue results.
- Fix task-queue logic that dequeues or cancels a task twice.
- In custom drivers/tests, construct a valid LoadResourceTask (via LoadResourceTask.Create) before calling Start.
- Add a null check after TryDequeue in any custom scheduling code.
Example fix
// before
LoadResourceTaskBase task = null;
agent.Start(task);
// after
if (m_TaskQueue.TryDequeue(out LoadResourceTaskBase task) && task != null)
{
agent.Start(task);
} Defensive patterns
Strategy: validation
Validate before calling
if (task == null) return StartTaskStatus.UnknownError; // guard before Start Debug.Assert(task != null, "Cannot start a null LoadResourceTask");
Type guard
bool IsValidTask(LoadResourceTaskBase t) => t != null;
Try / catch
try
{
var status = agent.Start(task);
}
catch (GameFrameworkException ex) when (ex.Message == "Task is invalid.")
{
Debug.LogError("Task queue produced a null task; check dequeue logic.");
} Prevention
- Let ResourceLoader manage the task queue; avoid calling Start directly.
- Null-check results of TryDequeue in custom scheduling code.
- Ensure tasks are not cancelled/dequeued twice.
- When driving agents in tests, build a real LoadResourceTask via LoadResourceTask.Create.
When it happens
Trigger: The internal task loop feeding a null LoadResourceTaskBase to an agent — possible when a task was consumed/removed twice, or custom code calls Start(null) directly.
Common situations: Custom modifications to the resource task queue (double dequeue, missing null check after TryDequeue); manually driving agents in unit tests without a task; version-upgrade code that changed task creation flow.
Related errors
- Load resource agent helper is invalid.
- Resource helper is invalid.
- Resource loader is invalid.
- Decrypt resource callback is invalid.
- Task agent is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/5416847f327c07e4.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Resource/ResourceManager.ResourceLoader.LoadResourceAgent.cs:147
}
public static void Clear()
{
s_CachedResourceNames.Clear();
s_LoadingAssetNames.Clear();
s_LoadingResourceNames.Clear();
}
/// <summary>
/// 开始处理加载资源任务。
/// </summary>
/// <param name="task">要处理的加载资源任务。</param>
/// <returns>开始处理任务的状态。</returns>
public StartTaskStatus Start(LoadResourceTaskBase task)
{
if (task == null)
{
throw new GameFrameworkException("Task is invalid.");
}
m_Task = task;
m_Task.StartTime = DateTime.UtcNow;
ResourceInfo resourceInfo = m_Task.ResourceInfo;
if (!resourceInfo.Ready)
{
m_Task.StartTime = default(DateTime);
return StartTaskStatus.HasToWait;
}
if (IsAssetLoading(m_Task.AssetName))
{
m_Task.StartTime = default(DateTime);
return StartTaskStatus.HasToWait;
}
View on GitHub (pinned to d0c010b051)