Skip to content

Commit

Permalink
#5387: Work around a problem in wxGTK 3.0.5+: invoke ItemsDeleted bef…
Browse files Browse the repository at this point in the history
…ore actually clearing the tree and invoking Cleared()
  • Loading branch information
codereader committed Nov 14, 2020
1 parent 3e08dce commit c7b161c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions libs/wxutil/TreeModel.cpp
Expand Up @@ -274,8 +274,21 @@ TreeModel::Row TreeModel::GetRootItem()

void TreeModel::Clear()
{
_rootNode->values.clear();
// To work around a problem in wxGTK 3.0.5+, trigger
// an ItemRemoved call for all top-level children before
// actually deleting them.
// The Cleared() call below might query GetParent() calls
// for nodes that are still present in the internal tree
wxDataViewItemArray children;
GetChildren(_rootNode->item, children);

if (!children.empty())
{
ItemsDeleted(_rootNode->item, children);
}

// Now it should be safe to free all the nodes
_rootNode->values.clear();
_rootNode->children.clear();

Cleared();
Expand Down Expand Up @@ -576,7 +589,7 @@ wxDataViewItem TreeModel::GetParent(const wxDataViewItem& item) const
// It's ok to ask for invisible root node's parent
if (!item.IsOk())
{
return wxDataViewItem(NULL);
return wxDataViewItem(NULL);
}

Node* owningNode = static_cast<Node*>(item.GetID());
Expand Down

0 comments on commit c7b161c

Please sign in to comment.