egametang/ET · error
invalid capacity: {capacity}
Error message
invalid capacity: {capacity} What it means
Thrown by the SERVER-side ItemComponentSystem.SetCapacity when capacity < 0. SetCapacity writes self.Capacity and then grows the SlotItems container via EnsureSlotContainerSize. A negative capacity is meaningless for a slot list, so the guard rejects it hard. Note the CLIENT-side SetCapacity (Client/ItemComponentSystem.cs:76) does NOT throw — it logs and returns — so this throw is server-authoritative only.
Source
Thrown at Packages/cn.etetet.item/Scripts/Hotfix/Server/ItemComponentSystem.cs:150
{
item.Dispose();
}
self.SlotItems[i] = default;
}
}
#endregion
#region 业务辅助方法
/// <summary>
/// 设置背包容量
/// </summary>
public static void SetCapacity(this ItemComponent self, int capacity)
{
if (capacity < 0)
{
throw new Exception($"invalid capacity: {capacity}");
}
self.Capacity = capacity;
EnsureSlotContainerSize(self, capacity);
}
/// <summary>
/// 清空指定槽位
/// </summary>
public static void ClearSlot(this ItemComponent self, int slotIndex)
{
if ((uint)slotIndex >= (uint)self.SlotItems.Count)
{
return;
}
self.SlotItems[slotIndex] = default;
}View on GitHub (pinned to 5cab01f7a8)
Solutions
- Clamp the computed capacity to >= 0 before calling SetCapacity (e.g. Math.Max(0, computed)).
- Fix the config sentinel: make 'not found' return 0 or a real default, never -1.
- Add a precondition at the caller (ItemHelper.SetCapacity) so the raw server API never sees a negative value.
Example fix
// before int cap = configTable.Get(player.Level); // returns -1 when missing component.SetCapacity(cap); // after int cap = configTable.Get(player.Level); if (cap < 0) cap = 0; // explicit default component.SetCapacity(cap);
Defensive patterns
Strategy: validation
Validate before calling
int safeCap = capacity < 0 ? 0 : capacity; component.SetCapacity(safeCap);
Prevention
- Never use -1 as a 'not found' sentinel for capacity; use 0 or a nullable.
- Clamp config-driven capacity to >= 0 at the data source.
- Unit-test SetCapacity with boundary values (0, negative, large).
When it happens
Trigger: Calling the server extension ItemComponentSystem.SetCapacity(this ItemComponent, int) (line 146) with a negative int. Reached from ItemHelper.SetCapacity (line 14) which forwards directly, or from any server code that computes capacity from player level/config and underflows.
Common situations: A config-driven capacity table returns -1 as a 'not found' sentinel and is passed straight in; an arithmetic underflow (e.g. baseCapacity - penalty where penalty > baseCapacity); a deserialized capacity field corrupted to a negative value.
Related errors
- slot index {slotIndex} exceeds capacity {self.Capacity}
- invalid slot index: {slotIndex}
- invalid item count
- item config not found: {configId}
- bag is full
AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13).
Data as JSON: /api/errors/6177d264e0287c5c.
Report an issue: GitHub.