EllanJiang/GameFramework · error · GameFrameworkException

Results is invalid.

Error message

Results is invalid.

What it means

GetObjectPools(Predicate<ObjectPoolBase>, List<ObjectPoolBase>) requires a non-null results list because it clears and fills it with matching pools. A null list throws GameFrameworkException("Results is invalid.").

Solutions

  1. Create and pass a List<ObjectPoolBase> instance; the method clears it before filling.
  2. Null-check/new-up the list before calling.
  3. Use the overload GetObjectPools(Predicate) that allocates and returns the array for you.

Example fix

// before
List<ObjectPoolBase> buffer; // null
objectPoolComponent.GetObjectPools(p => p.Priority > 0, buffer);
// after
List<ObjectPoolBase> buffer = new List<ObjectPoolBase>();
objectPoolComponent.GetObjectPools(p => p.Priority > 0, buffer);
Defensive patterns

Strategy: validation

Validate before calling

if (results == null) results = new List<ObjectPoolBase>();
objectPoolComponent.GetObjectPools(condition, results);

Type guard

static bool IsValidResults(List<ObjectPoolBase> l) => l != null;

Try / catch

try { objectPoolComponent.GetObjectPools(condition, results); }
catch (GameFrameworkException ex) when (ex.Message == "Results is invalid.") { results = new List<ObjectPoolBase>(); }

Prevention

When it happens

Trigger: Calling GetObjectPools(condition, null) — passing an uninitialized list field, or a method parameter that was null when forwarded.

Common situations: Reuse-buffer patterns where the cached List was never created; forwarding another method's null argument; assuming the method allocates the list for you (the non-list overload does).

Related errors


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

Appendix: source

Thrown at GameFramework/ObjectPool/ObjectPoolManager.cs:294

            return results.ToArray();
        }

        /// <summary>
        /// 获取对象池。
        /// </summary>
        /// <param name="condition">要检查的条件。</param>
        /// <param name="results">要获取的对象池。</param>
        public void GetObjectPools(Predicate<ObjectPoolBase> condition, List<ObjectPoolBase> results)
        {
            if (condition == null)
            {
                throw new GameFrameworkException("Condition is invalid.");
            }

            if (results == null)
            {
                throw new GameFrameworkException("Results is invalid.");
            }

            results.Clear();
            foreach (KeyValuePair<TypeNamePair, ObjectPoolBase> objectPool in m_ObjectPools)
            {
                if (condition(objectPool.Value))
                {
                    results.Add(objectPool.Value);
                }
            }
        }

        /// <summary>
        /// 获取所有对象池。
        /// </summary>
        /// <returns>所有对象池。</returns>
        public ObjectPoolBase[] GetAllObjectPools()
        {

View on GitHub (pinned to d0c010b051)