Bug ? refreshComponentForRow called on empty list

I have a ListBoxModel that returns 0 in its getNumRows method when not connected to a data source.

I expected the refreshComponentForRow to not be called (since list is empty), but it’s called twice with rows 0 and 1 during addAndMakeVisible.

Why is that so ? Shouldn’t getNumRows have authority on the rows created or updated ?

A range verification in ListViewport::updateContents could fix this problem:

    void updateContents()
        hasUpdated = true;
        const int rowHeight = owner.getRowHeight();
        const int rowCount = owner.getModel() ? owner.getModel()->getNumRows() : 0;

                    if (row < rowCount)
                        rowComp->update (row, owner.isRowSelected (row));

Well, it’s a good question, but not something that needs fixing.

There aren’t supposed to be exactly the same number of row components as there are items in the list. The row components are re-used, get moved around, and may be empty, so your refreshComponentForRow method must be able to deal with rows that are out-of-range.

I could add code to make sure there are no row components unless there are > 0 items, but it’d be pointless in terms of performance. And I think the code you suggested there would probably cause problems when the list shrinks in size.

Ok, I get it. I’ll check pointers in refreshComponentForRow.