Skip to content
Permalink
Browse files

Don't dereference deleted node

  • Loading branch information
elpaso committed Nov 9, 2020
1 parent d490755 commit c9133083298b1a9223f2abfb223a00ca8510b079
Showing with 14 additions and 6 deletions.
  1. +14 −6 src/core/layertree/qgslayertreenode.cpp
@@ -285,22 +285,30 @@ void QgsLayerTreeNode::removeChildrenPrivate( int from, int count, bool destroy
if ( to >= mChildren.count() )
return;

// Remove in reverse order
while ( --count >= 0 )
{
QgsLayerTreeNode *node = mChildren.at( from );
const int last { from + count };
Q_ASSERT( last >= 0 && last < mChildren.count( ) );
QgsLayerTreeNode *node = mChildren.at( last );

// Remove children first
if ( ! node->children().isEmpty() )
{
node->removeChildrenPrivate( 0, node->children().count(), destroy );
node->removeChildrenPrivate( 0, node->children().count( ), destroy );
}

emit willRemoveChildren( this, from, from );
node = mChildren.takeAt( from );
emit willRemoveChildren( this, last, last );
node = mChildren.takeAt( last );
if ( destroy )
{
delete node;
node->makeOrphan();
emit removedChildren( this, from, from );
}
else
{
node->makeOrphan();
}
emit removedChildren( this, last, last );
}
}

0 comments on commit c913308

Please sign in to comment.
You can’t perform that action at this time.