egametang/ET · error
invalid slot index: {slotIndex}
Error message
invalid slot index: {slotIndex} What it means
Thrown by the SERVER-side ItemComponentSystem.EnsureSlotIndex when slotIndex < 0. EnsureSlotIndex is the guard inside server SetSlotItem (line 175) and is the first of two checks (negative, then over-capacity). A negative index is always a programming error since valid slots are 0..Capacity-1.
Source
Thrown at Packages/cn.etetet.item/Scripts/Hotfix/Server/ItemComponentSystem.cs:200
/// <summary>
/// 尝试获取指定槽位的物品
/// </summary>
public static Item TryGetSlotItem(this ItemComponent self, int slotIndex)
{
if ((uint)slotIndex < (uint)self.SlotItems.Count)
{
return self.SlotItems[slotIndex];
}
return null;
}
private static void EnsureSlotIndex(ItemComponent self, int slotIndex)
{
if (slotIndex < 0)
{
throw new Exception($"invalid slot index: {slotIndex}");
}
if (slotIndex >= self.Capacity)
{
throw new Exception($"slot index {slotIndex} exceeds capacity {self.Capacity}");
}
}
private static void EnsureSlotContainerSize(ItemComponent self, int size)
{
if (size <= 0)
{
return;
}
if (self.SlotItems.Count >= size)
{
return;View on GitHub (pinned to 5cab01f7a8)
Solutions
- Always check FindEmptySlot() >= 0 before using the result (see ItemHelper.AddItem line 78 for the correct pattern).
- If storing a sentinel for 'no slot', use a nullable int or a separate flag, never -1 in a field that flows into SetSlotItem.
- Audit server code that constructs slotIndex from arithmetic and clamp at >= 0.
Example fix
// before
int slot = component.FindEmptySlot();
component.SetSlotItem(slot, item); // slot may be -1
// after
int slot = component.FindEmptySlot();
if (slot < 0) { /* handle full bag */ return; }
component.SetSlotItem(slot, item); Defensive patterns
Strategy: validation
Validate before calling
int slot = component.FindEmptySlot();
if (slot < 0) { /* bag full or no slot */ return; }
component.SetSlotItem(slot, item); Prevention
- Always check FindEmptySlot() >= 0 before using the result.
- Don't store -1 in a SlotIndex field; use a separate 'empty' flag.
- Centralize slot allocation through one helper that validates.
When it happens
Trigger: A server caller passes a negative slotIndex to SetSlotItem (e.g. the result of FindEmptySlot == -1 used without checking). FindEmptySlot returns -1 to mean 'no slot', so feeding that straight into SetSlotItem triggers this exact throw.
Common situations: Using FindEmptySlot()'s return value without testing for -1; an off-by-one in a loop that decrements past zero; a deserialized SlotIndex that was never initialized (default 0 is fine, but -1 used as an 'empty' marker persists into storage).
Related errors
- slot index {slotIndex} exceeds capacity {self.Capacity}
- invalid capacity: {capacity}
- invalid item count
- slot index {slotIndex} exceeds capacity {self.Capacity}
- item config not found: {configId}
AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13).
Data as JSON: /api/errors/d414c57a44320201.
Report an issue: GitHub.