EllanJiang/GameFramework · error · GameFrameworkException
Capacity is invalid.
Error message
Capacity is invalid.
What it means
An object pool's Capacity is the maximum number of objects it may hold; a negative capacity is nonsensical, so the Capacity setter throws 'Capacity is invalid.' This guards the pool's auto-shrink/eviction math which depends on non-negative capacity (0 means unlimited).
Solutions
- Set Capacity to a non-negative integer (0 for unlimited)
- Clamp the value before assigning: Math.Max(0, computedCapacity)
- Fix the config/source supplying the negative number and validate at load time
Example fix
// before pool.Capacity = config.PoolCapacity; // may be -1 // after pool.Capacity = Math.Max(0, config.PoolCapacity);
Defensive patterns
Strategy: validation
Validate before calling
if (capacity < 0) capacity = 0; // 0 = unlimited pool.Capacity = capacity;
Type guard
bool IsValidCapacity(int c) => c >= 0;
Try / catch
try { pool.Capacity = capacity; }
catch (GameFrameworkException ex) { Log.Error("Invalid pool capacity {0}", capacity); } Prevention
- Validate config values on load
- Clamp computed capacities with Math.Max(0, x)
- Restrict UI inputs to non-negative values
When it happens
Trigger: Assigning objectPool.Capacity = -1, typically from an unvalidated config value, a subtraction underflow (e.g. capacity - removedCount), or a misparsed settings file.
Common situations: Config-driven pool sizing where the config file has a negative number; computing capacity from another value that becomes negative; UI input allowing negatives.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- ExpireTime is invalid.
- Packet header length is invalid.
- Target ' ' is invalid.
- Object is invalid.
- Object ' ' spawn count is less than 0.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/27795926be121e68.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/ObjectPool/ObjectPoolManager.ObjectPool.cs:131
{
m_AutoReleaseInterval = value;
}
}
/// <summary>
/// 获取或设置对象池的容量。
/// </summary>
public override int Capacity
{
get
{
return m_Capacity;
}
set
{
if (value < 0)
{
throw new GameFrameworkException("Capacity is invalid.");
}
if (m_Capacity == value)
{
return;
}
m_Capacity = value;
Release();
}
}
/// <summary>
/// 获取或设置对象池对象过期秒数。
/// </summary>
public override float ExpireTime
{
getView on GitHub (pinned to d0c010b051)