EllanJiang/GameFramework · error · GameFrameworkException

Range is invalid.

Error message

Range is invalid.

What it means

GameFrameworkLinkedListRange<T> represents a contiguous segment of a LinkedList<T> defined by a first node and a terminal sentinel node. The constructor throws when first or terminal is null, or when both reference the same node, because such a range is structurally meaningless and would break traversal logic (range iteration stops at the terminal node).

Solutions

  1. Obtain first and terminal nodes from the same non-empty LinkedList<T>, ensuring first != terminal.
  2. Check that the searched node exists (Find/FindFirst not null) before constructing the range.
  3. Use the list's own range-creation helpers if provided rather than constructing nodes manually.
  4. Catch GameFrameworkException around range construction when node availability is uncertain.

Example fix

// before
var range = new GameFrameworkLinkedListRange<int>(list.Find(key), list.First); // may be null/equal
// after
var first = list.Find(key);
var terminal = list.First;
if (first != null && terminal != null && first != terminal)
{
    var range = new GameFrameworkLinkedListRange<int>(first, terminal);
}
Defensive patterns

Strategy: validation

Validate before calling

if (first == null || terminal == null || first == terminal) { throw new ArgumentException("Range nodes are invalid."); }
var range = new GameFrameworkLinkedListRange<T>(first, terminal);

Type guard

static bool IsValidRange<T>(LinkedListNode<T> first, LinkedListNode<T> terminal) => first != null && terminal != null && first != terminal;

Try / catch

try { var range = new GameFrameworkLinkedListRange<T>(first, terminal); } catch (GameFrameworkException) { /* skip empty/invalid span */ }

Prevention

When it happens

Trigger: Calling `new GameFrameworkLinkedListRange<T>(null, terminal)`, `(first, null)`, or `(node, node)` with the same LinkedListNode<T> for both parameters; also indirectly via any API that builds a range from empty or malformed linked-list state.

Common situations: Creating a range from a node obtained from an empty list (Find returns null), or accidentally passing the terminal sentinel as the first node; storing ranges across list modifications that orphaned the nodes.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/90aa505613b1ebcf. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Base/GameFrameworkLinkedListRange.cs:33

    /// 游戏框架链表范围。
    /// </summary>
    /// <typeparam name="T">指定链表范围的元素类型。</typeparam>
    [StructLayout(LayoutKind.Auto)]
    public struct GameFrameworkLinkedListRange<T> : IEnumerable<T>, IEnumerable
    {
        private readonly LinkedListNode<T> m_First;
        private readonly LinkedListNode<T> m_Terminal;

        /// <summary>
        /// 初始化游戏框架链表范围的新实例。
        /// </summary>
        /// <param name="first">链表范围的开始结点。</param>
        /// <param name="terminal">链表范围的终结标记结点。</param>
        public GameFrameworkLinkedListRange(LinkedListNode<T> first, LinkedListNode<T> terminal)
        {
            if (first == null || terminal == null || first == terminal)
            {
                throw new GameFrameworkException("Range is invalid.");
            }

            m_First = first;
            m_Terminal = terminal;
        }

        /// <summary>
        /// 获取链表范围是否有效。
        /// </summary>
        public bool IsValid
        {
            get
            {
                return m_First != null && m_Terminal != null && m_First != m_Terminal;
            }
        }

        /// <summary>

View on GitHub (pinned to d0c010b051)