EllanJiang/GameFramework · error · GameFrameworkException
Results is invalid.
Error message
Results is invalid.
What it means
GetAllFsms fills the provided list with all finite state machines registered in the FsmManager. The library throws GameFrameworkException("Results is invalid.") when the results list argument is null, because it needs a caller-allocated list to clear and fill.
Solutions
- Instantiate the list before calling: GetAllFsms(new List<FsmBase>())
- Check the list for null before the call, or use a factory method that always returns a non-null list
- Wrap the call in try-catch for GameFrameworkException if the list source is external/untrusted
Example fix
// before List<FsmBase> results = GetListFromCache(); // may be null fsmManager.GetAllFsms(results); // after List<FsmBase> results = GetListFromCache() ?? new List<FsmBase>(); fsmManager.GetAllFsms(results);
Defensive patterns
Strategy: validation
Validate before calling
if (results == null) results = new List<FsmBase>(); fsmManager.GetAllFsms(results);
Try / catch
try { fsmManager.GetAllFsms(results); }
catch (GameFrameworkException ex) { Log.Error("GetAllFsms failed: {0}", ex.Message); } Prevention
- Never pass null collections as output parameters
- Initialize list fields at declaration
- Prefer the overload that returns a new collection if available
When it happens
Trigger: Calling FsmManager.GetAllFsms(null) — the only condition that raises this exception, checked at the very top of the method.
Common situations: Passing an uninitialized field or a method result that was null instead of an instantiated List<FsmBase>; refactoring code so a list variable became nullable; copying an overload pattern where the container was never created.
Related errors
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/ce34a2061bca99dc.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Fsm/FsmManager.cs:224
int index = 0;
FsmBase[] results = new FsmBase[m_Fsms.Count];
foreach (KeyValuePair<TypeNamePair, FsmBase> fsm in m_Fsms)
{
results[index++] = fsm.Value;
}
return results;
}
/// <summary>
/// 获取所有有限状态机。
/// </summary>
/// <param name="results">所有有限状态机。</param>
public void GetAllFsms(List<FsmBase> results)
{
if (results == null)
{
throw new GameFrameworkException("Results is invalid.");
}
results.Clear();
foreach (KeyValuePair<TypeNamePair, FsmBase> fsm in m_Fsms)
{
results.Add(fsm.Value);
}
}
/// <summary>
/// 创建有限状态机。
/// </summary>
/// <typeparam name="T">有限状态机持有者类型。</typeparam>
/// <param name="owner">有限状态机持有者。</param>
/// <param name="states">有限状态机状态集合。</param>
/// <returns>要创建的有限状态机。</returns>
public IFsm<T> CreateFsm<T>(T owner, params FsmState<T>[] states) where T : class
{View on GitHub (pinned to d0c010b051)