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
- Only call Start with a task obtained from DownloadManager's task queue
- Check the task dequeuing logic for null when no task is available
- 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
- Dequeue tasks only through DownloadManager's own queue logic
- Handle empty-queue cases explicitly instead of passing null
- Never cache task references that may be nulled on shutdown
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
- Download agent helper is invalid.
- Task agent is invalid.
- Results is invalid.
- Offset is invalid.
- Length is invalid.
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)