Unity-Technologies/UnityCsReference · error · ArgumentOutOfRangeException

Input row index: {0} is invalid. Number of rows rects: {1}.

Error message

Input row index: {0} is invalid. Number of rows rects: {1}. (Number of rows: {2})

What it means

Thrown by TreeViewControlGUI.GetRowRect (when custom row rects are enabled) when the requested row index is outside [0, m_RowRects.Count). This indicates the row-rect array is out of sync with the actual number of rows, or an invalid index was passed.

Source

Thrown at Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControlGUI.cs:240

                {
                    acceptedRename = renameState.userAcceptedRename,
                    itemID = renameState.userData,
                    originalName = renameState.originalName,
                    newName = renameState.name
                };
                m_Owner.RenameEnded(renameEndedArgs);
            }

            public override Rect GetRowRect(int row, float rowWidth)
            {
                if (!useCustomRowRects)
                {
                    return base.GetRowRect(row, rowWidth);
                }

                if (row < 0 || row >= m_RowRects.Count)
                {
                    throw new ArgumentOutOfRangeException("row", string.Format("Input row index: {0} is invalid. Number of rows rects: {1}. (Number of rows: {2})", row, m_RowRects.Count, m_Owner.m_DataSource.rowCount));
                }

                Rect rowRect = m_RowRects[row];
                rowRect.width = rowWidth;
                return rowRect;
            }

            public override Rect GetRectForFraming(int row)
            {
                return GetRowRect(row, 1);
            }

            // Should return the row number of the first and last row thats fits in the pixel rect defined by top and height
            public override void GetFirstAndLastRowVisible(out int firstRowVisible, out int lastRowVisible)
            {
                if (!useCustomRowRects)
                {
                    base.GetFirstAndLastRowVisible(out firstRowVisible, out lastRowVisible);

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Call RefreshRowRects (via RefreshCustomRowHeights) after rebuilding rows to keep m_RowRects in sync.
  2. Ensure GetCustomRowHeight is overridden and returns a height for every row index.
  3. Clamp or guard the requested index against m_RowRects.Count before calling GetRowRect.

Example fix

// before
var rect = gui.GetRowRect(row, width); // row out of range

// after
treeView.RefreshCustomRowHeights(); // ensure rects are current
var rect = gui.GetRowRect(Mathf.Clamp(row, 0, rowCount - 1), width);
Defensive patterns

Strategy: validation

Validate before calling

treeView.RefreshCustomRowHeights();
int safeRow = Mathf.Clamp(row, 0, gui.m_RowRects.Count - 1);
var rect = gui.GetRowRect(safeRow, width);

Type guard

static bool IsValidRowIndex(int row, int rectCount) => row >= 0 && row < rectCount;

Prevention

When it happens

Trigger: Calling GetRowRect with an index >= the number of custom row rects; m_RowRects not refreshed after a Reload/BuildRows that changed the row count; requesting a row index before RefreshRowRects was called.

Common situations: Custom row heights enabled but RefreshRowRects was not called after the data changed; a scrolling/rendering path requesting a row index that was just removed; mismatch between rowCount and m_RowRects.Count.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/f1c9ed8c98204967. Report an issue: GitHub.