EllanJiang/GameFramework · error · GameFrameworkException
Condition is invalid.
Error message
Condition is invalid.
What it means
ObjectPoolManager.HasObjectPool requires a Predicate<ObjectPoolBase> to test each pool against. When the condition delegate is null there is no predicate to evaluate, so the manager throws GameFrameworkException("Condition is invalid.") to fail fast instead of throwing NullReferenceException mid-iteration.
Solutions
- Ensure a non-null predicate is passed, e.g. pool => true to match any pool.
- Check the condition for null before calling HasObjectPool and skip or substitute a default predicate.
- If the predicate comes from configuration, validate it was actually constructed before use.
Example fix
// before bool has = objectPoolComponent.HasObjectPool(myPredicate); // myPredicate is null // after if (myPredicate == null) myPredicate = pool => true; bool has = objectPoolComponent.HasObjectPool(myPredicate);
Defensive patterns
Strategy: validation
Validate before calling
if (condition == null) throw new ArgumentNullException(nameof(condition)); bool has = objectPoolComponent.HasObjectPool(condition);
Type guard
static bool IsValidPredicate(Predicate<ObjectPoolBase> p) => p != null;
Try / catch
try { bool has = objectPoolComponent.HasObjectPool(condition); }
catch (GameFrameworkException ex) when (ex.Message == "Condition is invalid.") { /* supply default predicate or log */ } Prevention
- Never pass null to mean 'match all'; use pool => true.
- Initialize delegate fields with a default predicate.
- Prefer LINQ-free explicit predicates over conditionally-built ones where possible.
When it happens
Trigger: Calling HasObjectPool(Predicate<ObjectPoolBase>) with a null condition argument, e.g. passing an uninitialized delegate variable or a method group that resolved to null.
Common situations: Building the predicate dynamically from user/config input where a filter expression ends up null; storing the predicate in a field that was never assigned; refactoring that removed the lambda but kept the call.
Related errors
- Results is invalid.
- Owner is invalid.
- Resource manager is invalid.
- Data provider helper is invalid.
- Type is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/1a7a8c51bcc91e45.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/ObjectPool/ObjectPoolManager.cs:157
if (!typeof(ObjectBase).IsAssignableFrom(objectType))
{
throw new GameFrameworkException(Utility.Text.Format("Object type '{0}' is invalid.", objectType.FullName));
}
return InternalHasObjectPool(new TypeNamePair(objectType, name));
}
/// <summary>
/// 检查是否存在对象池。
/// </summary>
/// <param name="condition">要检查的条件。</param>
/// <returns>是否存在对象池。</returns>
public bool HasObjectPool(Predicate<ObjectPoolBase> condition)
{
if (condition == null)
{
throw new GameFrameworkException("Condition is invalid.");
}
foreach (KeyValuePair<TypeNamePair, ObjectPoolBase> objectPool in m_ObjectPools)
{
if (condition(objectPool.Value))
{
return true;
}
}
return false;
}
/// <summary>
/// 获取对象池。
/// </summary>
/// <typeparam name="T">对象类型。</typeparam>
/// <returns>要获取的对象池。</returns>View on GitHub (pinned to d0c010b051)