Small patch to treelistctrl.cpp to avoid segfault problem
with freed m_key_current. (was handled in Delete(), but not in DeleteChildren()
and DeleteAllItems() ).
If this patch is obsolete in newest version, please ignore.
<------- snip ----->
inline
void wxTreeListMainWindow::DeleteChildren(const wxTreeItemId& itemId)
{
m_dirty = TRUE; // do this first so stuff below doesn't cause flicker
wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem;
// mst:16.10.03
// moved from Delete()
// don't stay with invalid m_key_current or we will crash in
// the next call to OnChar()
wxTreeListItem *itemKey = m_key_current;
while ( itemKey )
{
if ( itemKey == item )
{
// m_key_current is a descendant of the item which childrens being deleted
m_key_current = item;
break;
}
itemKey = itemKey->GetParent();
}
item->DeleteChildren(this);
}
inline
void wxTreeListMainWindow::Delete(const wxTreeItemId& itemId)
{
m_dirty = TRUE; // do this first so stuff below doesn't cause flicker
wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem;
// mst:16.10.03
item->DeleteChildren(this);
wxTreeListItem *parent = item->GetParent();
if ( parent )
parent->GetChildren().Remove( item ); // remove by value
if (m_key_current == item)
m_key_current = parent;
SendDeleteEvent(item);
delete item;
}
inline
void wxTreeListMainWindow::DeleteAllItems()
{
if ( m_anchor )
{
m_dirty = TRUE;
m_key_current = NULL; // mst:16.10.03
m_anchor->DeleteChildren(this);
delete m_anchor;
m_anchor = NULL;
}
}
<------- snip ----->
Greetings
Martin Stover <mstover@gmx.de>