-
Notifications
You must be signed in to change notification settings - Fork 29
Description
I've found a somewhat complicated bug involving Table.TopIndex - under certain usages, it seems that the value gets corrupted, causing the table to layout rows in the wrong order.
Specifically, the circumstances to reproduce it are as follows:
- Add enough rows to a table such that there are rows below the bottom visible edge of the table.
- Scroll down and remove the last row.
- Note that sometimes the table does not scroll up to remove empty whitespace at the bottom of the table created by removing the last row.
- Repeat removing the last row until rows are deleted offscreen.
- Table.topIndex is now corrupted, and the scrollbars/row layout act very strangely.
It seems that to reproduce this it is necessary to use BeginUpdate() and EndUpdate(). Specifically, whenever my "data model" changes, I "update" the table by clearing it entirely and refilling it:
private void ReloadTable()
{
int selectedRow = SelectedRowIndex;
table.BeginUpdate();
tableModel.Rows.Clear();
foreach( int value in data )
{
Row row = new Row();
row.Cells.Add( new Cell( value ) );
tableModel.Rows.Add( row );
}
table.EndUpdate();
// Restore selection.
if( selectedRow != -1 )
{
int row = Math.Min( selectedRow, tableModel.Rows.Count - 1 );
tableModel.Selections.Clear();
tableModel.Selections.SelectCell( row, 0 );
}
}
Since this is a slightly complicated bug to understand, I've attached a demo program and a video of me reproducing the bug. In order to make the demo program work, I've had to make a few mods to Table.cs for debugging (be able to modify TopIndex and also catch an event when it changes).
I've attached a zip file containing my demo program and a video of me reproducing the bug, as well as a patch file showing the changes I needed to make to Table.cs to make the demo program.