diff --git a/src/AcDream.App/UI/UiItemList.cs b/src/AcDream.App/UI/UiItemList.cs index df77f47e..761d4db3 100644 --- a/src/AcDream.App/UI/UiItemList.cs +++ b/src/AcDream.App/UI/UiItemList.cs @@ -24,8 +24,14 @@ public sealed class UiItemList : UiElement public Func? SpriteResolve { get; set; } - /// Convenience for single-cell slots (the toolbar): the first cell. - public UiItemSlot Cell => _cells[0]; + /// Convenience for single-cell slots (the toolbar): the first cell. + /// Valid only while the list has at least one cell; after + /// (the inventory-phase rebuild path) the list is empty until + /// runs, so use there instead. + /// the list has no cells (e.g. after Flush). + public UiItemSlot Cell => _cells.Count > 0 + ? _cells[0] + : throw new InvalidOperationException("UiItemList has no cells; call AddItem first or use GetItem(index)."); public int GetNumUIItems() => _cells.Count;