EllanJiang/GameFramework · error · GameFrameworkException
Last is invalid.
Error message
Last is invalid.
What it means
GameFrameworkLinkedList<T>.RemoveLast tries to remove the last node of the underlying LinkedList and release it to the node pool. When the list's Last node is null (the list is empty), the wrapper throws this error rather than operating on an invalid state.
Solutions
- Check Count > 0 (or Last != null) before calling RemoveLast
- Restructure the drain loop as while (list.Count > 0) { list.RemoveLast(); }
- Catch GameFrameworkException around RemoveLast if an empty list is an expected, tolerable state
Example fix
// before
if (needPop) { list.RemoveLast(); }
// after
if (needPop && list.Count > 0) { list.RemoveLast(); } Defensive patterns
Strategy: validation
Validate before calling
if (list.Count > 0) { list.RemoveLast(); } Type guard
static bool CanRemoveLast<T>(GameFrameworkLinkedList<T> list) => list != null && list.Count > 0;
Try / catch
try { list.RemoveLast(); }
catch (GameFrameworkException) { /* list already empty; treat as no-op */ } Prevention
- Guard tail-pops with a Count > 0 check
- Keep single ownership of the list so no other path empties it unexpectedly
- Prefer while (list.Count > 0) loops over unbounded pop loops
When it happens
Trigger: Calling RemoveLast() on an empty GameFrameworkLinkedList — e.g. popping from the tail without checking whether any elements remain, or calling it twice after the list became empty.
Common situations: LIFO-style drains from the tail of a pooled linked list; off-by-one loops; interleaved code paths where another component already emptied the list.
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
- First 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/fa22f74ef6e4fb9c.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Base/GameFrameworkLinkedList.cs:322
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();
ReleaseNode(last);
}
/// <summary>
/// 返回循环访问集合的枚举数。
/// </summary>
/// <returns>循环访问集合的枚举数。</returns>
public Enumerator GetEnumerator()
{
return new Enumerator(m_LinkedList);
}
private LinkedListNode<T> AcquireNode(T value)
{
LinkedListNode<T> node = null;View on GitHub (pinned to d0c010b051)