EllanJiang/GameFramework · error · GameFrameworkException
Linked list is invalid.
Error message
Linked list is invalid.
What it means
GameFrameworkLinkedList<T> creates a nested Enumerator by calling linkedList.GetEnumerator() on a constructor argument. The library throws this GameFrameworkException when that argument is null, because enumerating requires a valid linked list instance. It is an eager fail-fast guard placed at the start of enumeration.
Solutions
- Ensure the GameFrameworkLinkedList wrapper is constructed properly so its internal LinkedList<T> is never null before enumerating.
- Add a null check on the source object before calling GetEnumerator()/foreach on it.
- If the wrapper came from Unity serialization, initialize the list in a constructor or Awake/OnEnable instead of relying on field serialization.
- Wrap enumeration in try-catch for GameFrameworkException if list availability cannot be guaranteed.
Example fix
// before
var enumerator = new GameFrameworkLinkedList<int>.Enumerator(null);
// after
if (linkedList == null) { linkedList = new LinkedList<int>(); }
var enumerator = new GameFrameworkLinkedList<int>.Enumerator(linkedList); Defensive patterns
Strategy: type-guard
Validate before calling
if (wrapper == null || wrapper.GetInternalLinkedList() == null) { return; } Type guard
static bool CanEnumerate<T>(GameFrameworkLinkedList<T> list) => list != null;
Try / catch
try { foreach (var item in list) { ... } } catch (GameFrameworkException) { /* treat as empty */ } Prevention
- Initialize internal LinkedList<T> in the wrapper constructor
- Null-check before foreach
- Avoid Unity-serializing non-serializable list wrappers without explicit init
When it happens
Trigger: Constructing GameFrameworkLinkedList<T>.Enumerator with a null LinkedList<T>, i.e. `new GameFrameworkLinkedList<T>.Enumerator(null)`, typically via GetEnumerator() on a wrapper whose internal list was never initialized.
Common situations: Calling foreach on a GameFrameworkLinkedList wrapper whose internal LinkedList<T> field was never assigned, or a default-constructed/serialized-without-init wrapper object whose m_LinkedList stayed null (common with Unity serialization of non-serializable fields).
Related errors
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/a2f893a89a4328bf.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Base/GameFrameworkLinkedList.cs:399
/// <returns>循环访问集合的枚举数。</returns>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
/// <summary>
/// 循环访问集合的枚举数。
/// </summary>
[StructLayout(LayoutKind.Auto)]
public struct Enumerator : IEnumerator<T>, IEnumerator
{
private LinkedList<T>.Enumerator m_Enumerator;
internal Enumerator(LinkedList<T> linkedList)
{
if (linkedList == null)
{
throw new GameFrameworkException("Linked list is invalid.");
}
m_Enumerator = linkedList.GetEnumerator();
}
/// <summary>
/// 获取当前结点。
/// </summary>
public T Current
{
get
{
return m_Enumerator.Current;
}
}
/// <summary>
/// 获取当前的枚举数。View on GitHub (pinned to d0c010b051)