EllanJiang/GameFramework · error · GameFrameworkException
First is invalid.
Error message
First is invalid.
What it means
GameFrameworkLinkedList<T>.RemoveFirst tries to remove the first node of the underlying LinkedList and release it back to the node pool. The list's First node is null (the list is empty), which the wrapper treats as an invalid state and throws instead of letting the raw list silently do nothing or throw its own error.
Solutions
- Check Count > 0 (or First != null) before calling RemoveFirst
- Use TryGetFirst/First value access guards or restructure the loop to use a while (list.Count > 0) condition
- Catch GameFrameworkException and treat empty list as a no-op if acceptable
Example fix
// before
while (true) { list.RemoveFirst(); }
// after
while (list.Count > 0) { list.RemoveFirst(); } Defensive patterns
Strategy: validation
Validate before calling
if (list.Count > 0) { list.RemoveFirst(); } Type guard
static bool CanRemoveFirst<T>(GameFrameworkLinkedList<T> list) => list != null && list.Count > 0;
Try / catch
try { list.RemoveFirst(); }
catch (GameFrameworkException) { /* list already empty; treat as no-op */ } Prevention
- Check Count before RemoveFirst/RemoveLast in drain loops
- Avoid calling RemoveFirst after Clear or after another consumer emptied the list
- Centralize pop logic in one helper that guards emptiness
When it happens
Trigger: Calling RemoveFirst() on an empty GameFrameworkLinkedList — e.g. draining a queue with RemoveFirst without checking Count, or after all nodes were already removed.
Common situations: Consumer loops popping from a pooled linked list until empty; double-drain after Clear; logic bugs where items were consumed elsewhere before RemoveFirst is called.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Last is invalid.
- Access is invalid.
- Already exist data table
- Already exist network channel
- appendErrorMessage
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/87e32308019f1f5d.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Base/GameFrameworkLinkedList.cs:307
/// <summary>
/// 从链表中移除指定的结点。
/// </summary>
/// <param name="node">指定的结点。</param>
public void Remove(LinkedListNode<T> node)
{
m_LinkedList.Remove(node);
ReleaseNode(node);
}
/// <summary>
/// 移除位于链表开头处的结点。
/// </summary>
public void RemoveFirst()
{
LinkedListNode<T> first = m_LinkedList.First;
if (first == null)
{
throw new GameFrameworkException("First is invalid.");
}
m_LinkedList.RemoveFirst();
ReleaseNode(first);
}
/// <summary>
/// 移除位于链表结尾处的结点。
/// </summary>
public void RemoveLast()
{
LinkedListNode<T> last = m_LinkedList.Last;
if (last == null)
{
throw new GameFrameworkException("Last is invalid.");
}
m_LinkedList.RemoveLast();View on GitHub (pinned to d0c010b051)