EllanJiang/GameFramework · error · GameFrameworkException
Data is invalid.
Error message
Data is invalid.
What it means
TaskInfo is a lightweight wrapper around task data in the TaskPool. Its properties (SerialId, etc.) throw 'Data is invalid.' when accessed while m_IsValid is false — i.e. after the task info has been reset/invalidated (for example when the task completed or was shut down and TaskInfo.Reset/invalidation ran). Accessing fields of a dead TaskInfo is a use-after-free-style bug in the task lifecycle.
Solutions
- Check the TaskInfo's valid state (IsValid / m_IsValid backing flag) before reading its properties.
- Copy needed values (SerialId, etc.) into your own fields while the task is still valid, rather than reading the TaskInfo later.
- Fix callback lifetimes: unsubscribe or guard callbacks so they do not run after the task info has been reset by shutdown or completion.
Example fix
// before
void OnDone(TaskInfo info) { Log(info.SerialId); } // may be invalid
// after
void OnDone(TaskInfo info)
{
int serialId = info.SerialId; // read while valid, inside task execution
... // or check IsValid / capture id at task start instead
} Defensive patterns
Strategy: try-catch
Validate before calling
// guard reads on a possibly-invalid TaskInfo
if (taskInfo.IsValid)
{
int id = taskInfo.SerialId;
} Type guard
bool TryGetSerialId(TaskInfo info, out int serialId)
{
serialId = 0;
try { serialId = info.SerialId; return true; }
catch (GameFrameworkException) { return false; }
} Try / catch
try
{
int serialId = taskInfo.SerialId;
}
catch (GameFrameworkException ex) when (ex.Message == "Data is invalid.")
{
// TaskInfo was reset (completed/cancelled/shutdown) — abandon stale reads
} Prevention
- Read TaskInfo properties only inside the task's execution window, not in later callbacks.
- Capture SerialId into a local/own field when the task starts if you need it after completion.
- Cancel or unsubscribe callbacks on TaskPool shutdown so they never touch invalidated TaskInfos.
When it happens
Trigger: Reading SerialId (or other properties) on a TaskInfo whose m_IsValid is false — typically after TaskPool task completion/shutdown reset the TaskInfo, but a callback, closure, or cached reference still holds and reads it asynchronously.
Common situations: Async completion callbacks firing after the task pool was shut down or the task was cancelled and its TaskInfo reset; storing TaskInfo references longer than the task's lifetime and reading them later; starve/shutdown paths invalidating infos while workers still inspect them.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- You must check resources complete first.
- You can not use StopUpdateResources at this time.
- The reference has been released.
- FSM is running, can not start again.
- Current state is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/686bed004e943598.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Base/TaskPool/TaskInfo.cs:66
/// </summary>
public bool IsValid
{
get
{
return m_IsValid;
}
}
/// <summary>
/// 获取任务的序列编号。
/// </summary>
public int SerialId
{
get
{
if (!m_IsValid)
{
throw new GameFrameworkException("Data is invalid.");
}
return m_SerialId;
}
}
/// <summary>
/// 获取任务的标签。
/// </summary>
public string Tag
{
get
{
if (!m_IsValid)
{
throw new GameFrameworkException("Data is invalid.");
}
View on GitHub (pinned to d0c010b051)