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

  1. Never call Start directly with null; let ResourceLoader's task loop manage tasks and check TryDequeue results.
  2. Fix task-queue logic that dequeues or cancels a task twice.
  3. In custom drivers/tests, construct a valid LoadResourceTask (via LoadResourceTask.Create) before calling Start.
  4. 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

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


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)