Skip to content

Commit c53e6df

Browse files
committed
fix: guard against stale row snapshot during render race
1 parent adc7ac5 commit c53e6df

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

SharpConsoleUI/Controls/TableControl/TableControl.Rendering.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,13 +747,16 @@ void FillSideMargins(int y)
747747
int dataStartY = currentY;
748748

749749
// Data rows - virtual rendering (only visible rows)
750-
int rowCount = RowCount;
750+
int rowCount = rowSnapshot?.Count ?? RowCount;
751751
int startRow = _scrollOffset;
752752
int endRow = Math.Min(rowCount, _scrollOffset + GetVisibleRowCount());
753753

754754
for (int displayR = startRow; displayR < endRow && currentY < maxY; displayR++)
755755
{
756756
int dataR = MapDisplayToData(displayR);
757+
// Guard against snapshot/data race — dataR may be invalid if _rows changed after snapshot
758+
if (rowSnapshot != null && (dataR < 0 || dataR >= rowSnapshot.Count))
759+
continue;
757760

758761
// Row separator (between rows, not before first)
759762
if (displayR > startRow && _showRowSeparators && hasBorder && currentY < maxY)

0 commit comments

Comments
 (0)