Hi Robin and others,
I'm pretty sure I discovered an off-by-one error in treelistctr.cpp.
Some context: Task Coach allows users to remove columns in two ways:
by means of a context menu that pops up when the user right-clicks a
column header or by means of the View->Columns regular menu. I was
experiencing crashes when removing the rightmost column in the
TreeListCtrl, with the message: "[Debug] 21:10:15:
contrib/gizmos/wxCode/src/treelistctrl.cpp(213): assert "(column >= 0)
&& (column < GetColumnCount())" failed in IsColumnShown(): Invalid
column"
The funny thing is that the crash only happens when using the context
menu; it does not happen when removing the column via the regular
menu. Apparently different code is executed when using the context
menu. I think it is the refreshing of the column label that happens
from the TreeListHeaderWindow::OnMouse method. That method invokes
TreeListHeaderWindow::RefreshColLabel:
void wxTreeListHeaderWindow::RefreshColLabel(int col)
{
if ( col > GetColumnCount() )
return;
int x = 0;
int width = 0;
int idx = 0;
do {
if (!IsColumnShown(idx)) continue;
wxTreeListColumnInfo& column = GetColumn(idx);
x += width;
width = column.GetWidth();
} while (++idx <= col);
m_owner->CalcScrolledPosition(x, 0, &x, NULL);
RefreshRect(wxRect(x, 0, width, GetSize().GetHeight()));
}
Look at the first line: if col == GetColumnCount() we proceed. In the
do-while loop idx is increased with col as maximum value. We then call
IsColumnShown with idx == GetColumnCount(). This triggers the assert
in IsColumnShown:
bool IsColumnShown (int column) const {
wxCHECK_MSG ((column >= 0) && (column < GetColumnCount()),
true, _T("Invalid column"));
return m_columns[column].IsShown();
}
I guess the fix is to change the first two lines of RefreshColLabel to read:
if ( col >= GetColumnCount() )
return
This is with wxPython 2.8.1 on both Windows and Mac OSX, but
treelistctrl.cpp doesn't seem to be changed for release 2.8.3 as far
as I can tell.
Cheers, Frank