{"record":{"id":"f1c9ed8c98204967","repo":"Unity-Technologies/UnityCsReference","slug":"input-row-index-0-is-invalid-number-of-rows-re","errorCode":null,"errorMessage":"Input row index: {0} is invalid. Number of rows rects: {1}. (Number of rows: {2})","messagePattern":"Input row index: (.+?) is invalid\\. Number of rows rects: (.+?)\\. \\(Number of rows: (.+?)\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControlGUI.cs","lineNumber":240,"sourceCode":"                {\n                    acceptedRename = renameState.userAcceptedRename,\n                    itemID = renameState.userData,\n                    originalName = renameState.originalName,\n                    newName = renameState.name\n                };\n                m_Owner.RenameEnded(renameEndedArgs);\n            }\n\n            public override Rect GetRowRect(int row, float rowWidth)\n            {\n                if (!useCustomRowRects)\n                {\n                    return base.GetRowRect(row, rowWidth);\n                }\n\n                if (row < 0 || row >= m_RowRects.Count)\n                {\n                    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));\n                }\n\n                Rect rowRect = m_RowRects[row];\n                rowRect.width = rowWidth;\n                return rowRect;\n            }\n\n            public override Rect GetRectForFraming(int row)\n            {\n                return GetRowRect(row, 1);\n            }\n\n            // Should return the row number of the first and last row thats fits in the pixel rect defined by top and height\n            public override void GetFirstAndLastRowVisible(out int firstRowVisible, out int lastRowVisible)\n            {\n                if (!useCustomRowRects)\n                {\n                    base.GetFirstAndLastRowVisible(out firstRowVisible, out lastRowVisible);","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControlGUI.cs#L222-L258","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Call RefreshRowRects (via RefreshCustomRowHeights) after rebuilding rows to keep m_RowRects in sync.","Ensure GetCustomRowHeight is overridden and returns a height for every row index.","Clamp or guard the requested index against m_RowRects.Count before calling GetRowRect."],"exampleFix":"// before\nvar rect = gui.GetRowRect(row, width); // row out of range\n\n// after\ntreeView.RefreshCustomRowHeights(); // ensure rects are current\nvar rect = gui.GetRowRect(Mathf.Clamp(row, 0, rowCount - 1), width);","handlingStrategy":"validation","validationCode":"treeView.RefreshCustomRowHeights();\nint safeRow = Mathf.Clamp(row, 0, gui.m_RowRects.Count - 1);\nvar rect = gui.GetRowRect(safeRow, width);","typeGuard":"static bool IsValidRowIndex(int row, int rectCount) => row >= 0 && row < rectCount;","tryCatchPattern":null,"preventionTips":["Call RefreshCustomRowHeights after rebuilding rows.","Ensure GetCustomRowHeight covers every row index.","Guard row indices against m_RowRects.Count."],"tags":["unity","treeview","custom-row-height","argument-out-of-range","rowrect"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}