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: http://svn.slicer.org/Slicer4/trunk@21529 3bd1e089-480b-0410-8dfb-8563597acbee
parent 232e681b
......@@ -666,12 +666,14 @@ void qMRMLSceneModel::updateScene()
preSceneItemCount,
this->rowCount() - preSceneItemCount - postSceneItemCount);
this->setColumnCount(oldColumnCount);
emit sceneUpdated();
return;
}
// if there is no column, there is no scene item.
if (!this->mrmlSceneItem())
{
emit sceneUpdated();
return;
}
......@@ -689,7 +691,7 @@ void qMRMLSceneModel::updateScene()
// Populate scene with nodes
this->populateScene();
emit this->sceneUpdated();
emit sceneUpdated();
}
//------------------------------------------------------------------------------
......
......@@ -234,13 +234,17 @@ void qMRMLTreeViewPrivate::saveChildrenExpandState(QModelIndex &parentIndex)
Q_Q(qMRMLTreeView);
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 &&
q->sortFilterProxyModel()->mrmlScene()->IsNodePresent(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(
q->sortFilterProxyModel()->mrmlNodeFromIndex(parentIndex));
if (parentNode)
{
vtkWeakPointer<vtkMRMLNode> weakNode =
vtkMRMLNode::SafeDownCast(parentNode);
this->ExpandedNodes->AddItem(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