EllanJiang/GameFramework · error · GameFrameworkException

Task is invalid.

Error message

Task is invalid.

What it means

DownloadAgent.Start requires a non-null DownloadTask because the agent needs the task's download URL, path, and tag to do any work. This error means Start was called with a null task, so the agent has nothing to process.

Solutions

  1. Only call Start with a task obtained from DownloadManager's task queue
  2. Check the task dequeuing logic for null when no task is available
  3. Ensure the task was created through DownloadManager.AddTask so it is properly formed

Example fix

// before
DownloadTask task = GetNextTask(); // may be null
agent.Start(task);
// after
DownloadTask task = GetNextTask();
if (task != null) agent.Start(task);
Defensive patterns

Strategy: type-guard

Validate before calling

if (task == null) return StartTaskStatus.UnknownError; // or skip iteration

Type guard

bool HasTask(DownloadTask task) => task != null;

Try / catch

try { agent.Start(task); } catch (GameFrameworkException ex) { Log.Error("Download agent start failed: {0}", ex.Message); }

Prevention

When it happens

Trigger: Calling DownloadAgent.Start(task) with task == null, usually from a custom DownloadManager task loop or when the task queue returned null.

Common situations: Custom scheduling code that pops from an empty/nullable task collection, passing a task struct boxed incorrectly, or initializing agents before tasks are queued.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/05d4ae11080c70c4. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Download/DownloadManager.DownloadAgent.cs:180

            {
                Dispose();

                m_Helper.DownloadAgentHelperUpdateBytes -= OnDownloadAgentHelperUpdateBytes;
                m_Helper.DownloadAgentHelperUpdateLength -= OnDownloadAgentHelperUpdateLength;
                m_Helper.DownloadAgentHelperComplete -= OnDownloadAgentHelperComplete;
                m_Helper.DownloadAgentHelperError -= OnDownloadAgentHelperError;
            }

            /// <summary>
            /// 开始处理下载任务。
            /// </summary>
            /// <param name="task">要处理的下载任务。</param>
            /// <returns>开始处理任务的状态。</returns>
            public StartTaskStatus Start(DownloadTask task)
            {
                if (task == null)
                {
                    throw new GameFrameworkException("Task is invalid.");
                }

                m_Task = task;

                m_Task.Status = DownloadTaskStatus.Doing;
                string downloadFile = Utility.Text.Format("{0}.download", m_Task.DownloadPath);

                try
                {
                    if (File.Exists(downloadFile))
                    {
                        m_FileStream = File.OpenWrite(downloadFile);
                        m_FileStream.Seek(0L, SeekOrigin.End);
                        m_StartLength = m_SavedLength = m_FileStream.Length;
                        m_DownloadedLength = 0L;
                    }
                    else
                    {

View on GitHub (pinned to d0c010b051)