{"record":{"id":"27795926be121e68","repo":"EllanJiang/GameFramework","slug":"capacity-is-invalid","errorCode":null,"errorMessage":"Capacity is invalid.","messagePattern":"Capacity is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/ObjectPool/ObjectPoolManager.ObjectPool.cs","lineNumber":131,"sourceCode":"                {\n                    m_AutoReleaseInterval = value;\n                }\n            }\n\n            /// <summary>\n            /// 获取或设置对象池的容量。\n            /// </summary>\n            public override int Capacity\n            {\n                get\n                {\n                    return m_Capacity;\n                }\n                set\n                {\n                    if (value < 0)\n                    {\n                        throw new GameFrameworkException(\"Capacity is invalid.\");\n                    }\n\n                    if (m_Capacity == value)\n                    {\n                        return;\n                    }\n\n                    m_Capacity = value;\n                    Release();\n                }\n            }\n\n            /// <summary>\n            /// 获取或设置对象池对象过期秒数。\n            /// </summary>\n            public override float ExpireTime\n            {\n                get","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/ObjectPool/ObjectPoolManager.ObjectPool.cs#L113-L149","documentation":"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).","triggerScenarios":"Assigning objectPool.Capacity = -1, typically from an unvalidated config value, a subtraction underflow (e.g. capacity - removedCount), or a misparsed settings file.","commonSituations":"Config-driven pool sizing where the config file has a negative number; computing capacity from another value that becomes negative; UI input allowing negatives.","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"],"exampleFix":"// before\npool.Capacity = config.PoolCapacity; // may be -1\n// after\npool.Capacity = Math.Max(0, config.PoolCapacity);","handlingStrategy":"validation","validationCode":"if (capacity < 0) capacity = 0; // 0 = unlimited\npool.Capacity = capacity;","typeGuard":"bool IsValidCapacity(int c) => c >= 0;","tryCatchPattern":"try { pool.Capacity = capacity; }\ncatch (GameFrameworkException ex) { Log.Error(\"Invalid pool capacity {0}\", capacity); }","preventionTips":["Validate config values on load","Clamp computed capacities with Math.Max(0, x)","Restrict UI inputs to non-negative values"],"tags":["objectpool","capacity","validation","gameframework"],"backgroundTag":"value-out-of-range","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}