Fix crash with wxDataViewVirtualListModel in generic wxDataViewCtrl

Recent sorting-related changes resulted in calling FindNode(), which
can only be used with the non-"virtual list" models, unconditionally,
after the items values was changed by user, resulting in a crash.

Add the missing IsVirtualList() check and also add a comment explicitly
stating that all code involving wxDataViewTreeNode can only be used
after checking that IsVirtualList() returns false.

Closes #18057.
This commit is contained in:
Vadim Zeitlin
2018-01-25 13:02:14 +01:00
parent c7599c8ec0
commit a9b44af251

View File

@@ -458,6 +458,11 @@ class wxDataViewTreeNode;
typedef wxVector<wxDataViewTreeNode*> wxDataViewTreeNodes; typedef wxVector<wxDataViewTreeNode*> wxDataViewTreeNodes;
// Note: this class is not used at all for virtual list models, so all code
// using it, i.e. any functions taking or returning objects of this type,
// including wxDataViewMainWindow::m_root, can only be called after checking
// that we're using a non-"virtual list" model.
class wxDataViewTreeNode class wxDataViewTreeNode
{ {
public: public:
@@ -2941,6 +2946,8 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
} }
bool wxDataViewMainWindow::DoItemChanged(const wxDataViewItem & item, int view_column) bool wxDataViewMainWindow::DoItemChanged(const wxDataViewItem & item, int view_column)
{
if ( !IsVirtualList() )
{ {
// Move this node to its new correct place after it was updated. // Move this node to its new correct place after it was updated.
// //
@@ -2953,6 +2960,7 @@ bool wxDataViewMainWindow::DoItemChanged(const wxDataViewItem & item, int view_c
wxDataViewTreeNode* const node = FindNode(item); wxDataViewTreeNode* const node = FindNode(item);
wxCHECK_MSG( node, false, "invalid item" ); wxCHECK_MSG( node, false, "invalid item" );
node->PutInSortOrder(this); node->PutInSortOrder(this);
}
wxDataViewColumn* column; wxDataViewColumn* column;
if ( view_column == wxNOT_FOUND ) if ( view_column == wxNOT_FOUND )