EllanJiang/GameFramework · error · GameFrameworkException

Results is invalid.

Error message

Results is invalid.

What it means

Null guard in Fsm<T>.GetAllStates(List<FsmState<T>>): thrown when the caller-supplied results list is null. This overload exists to let callers reuse a list and avoid allocation, so a null list defeats its purpose; pass an initialized List<FsmState<T>> or use the allocating overload.

Solutions

  1. Pass a newly allocated List<FsmState<T>> to GetAllStates
  2. Initialize the list field before the call
  3. Null-check the list argument before invoking

Example fix

// before
List<FsmState<FsmOwner>> states = null;
fsm.GetAllStates(states); // throws
// after
var states = new List<FsmState<FsmOwner>>();
fsm.GetAllStates(states);
Defensive patterns

Strategy: validation

Validate before calling

if (results == null) results = new List<FsmState<T>>();
fsm.GetAllStates(results);

Try / catch

try { fsm.GetAllStates(results); }
catch (GameFrameworkException ex) { Log.Error("GetAllStates requires a valid list: {0}", ex.Message); }

Prevention

When it happens

Trigger: Calling fsm.GetAllStates(null), typically when a list field was never initialized or a helper method forwards a null collection.

Common situations: Debug/inspection utilities enumerating states of an FSM; deferred initialization where the list member is allocated later than the call.

Related errors


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

Appendix: source

Thrown at GameFramework/Fsm/Fsm.cs:402

            int index = 0;
            FsmState<T>[] results = new FsmState<T>[m_States.Count];
            foreach (KeyValuePair<Type, FsmState<T>> state in m_States)
            {
                results[index++] = state.Value;
            }

            return results;
        }

        /// <summary>
        /// 获取有限状态机的所有状态。
        /// </summary>
        /// <param name="results">有限状态机的所有状态。</param>
        public void GetAllStates(List<FsmState<T>> results)
        {
            if (results == null)
            {
                throw new GameFrameworkException("Results is invalid.");
            }

            results.Clear();
            foreach (KeyValuePair<Type, FsmState<T>> state in m_States)
            {
                results.Add(state.Value);
            }
        }

        /// <summary>
        /// 是否存在有限状态机数据。
        /// </summary>
        /// <param name="name">有限状态机数据名称。</param>
        /// <returns>有限状态机数据是否存在。</returns>
        public bool HasData(string name)
        {
            if (string.IsNullOrEmpty(name))
            {

View on GitHub (pinned to d0c010b051)