Commit b70ae3bc authored by sankhesh's avatar sankhesh
Browse files

BUG: Need to check if node is present in scene before referencing

While deleting a node, there could be a reference dangling in the tree view that
needs can cause issues. Check if the node being worked on is present in the MRML
scene before referencing to it.
Fixes issue 2841

git-svn-id: 3bd1e089-480b-0410-8dfb-8563597acbee
parent 232e681b
......@@ -666,12 +666,14 @@ void qMRMLSceneModel::updateScene()
this->rowCount() - preSceneItemCount - postSceneItemCount);
emit sceneUpdated();
// if there is no column, there is no scene item.
if (!this->mrmlSceneItem())
emit sceneUpdated();
......@@ -689,7 +691,7 @@ void qMRMLSceneModel::updateScene()
// Populate scene with nodes
emit this->sceneUpdated();
emit sceneUpdated();
......@@ -234,13 +234,17 @@ void qMRMLTreeViewPrivate::saveChildrenExpandState(QModelIndex &parentIndex)
if (q->isExpanded(parentIndex))
// Check if the node is currently present in the scene.
// When a node/hierarchy is being deleted from the vtkMRMLScene, there is
// some reference of the deleted node left dangling in the qMRMLSceneModel.
// As a result, mrmlNodeFromIndex returns a reference to a non-existent node.
vtkMRMLNode* parentNode = q->sortFilterProxyModel()->mrmlNodeFromIndex(parentIndex);
if (parentNode &&
// Store a weak reference to the parentNode in the vtkCollection.
// This helps avoid any dangling references if the node was deleted
// while updating scene.
vtkMRMLNode* parentNode = vtkMRMLNode::SafeDownCast(
if (parentNode)
vtkWeakPointer<vtkMRMLNode> weakNode =
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment