Skip to content

Commit

Permalink
BUG: Adding missing null-pointer checks to qMRMLSegmentEditorWidget
Browse files Browse the repository at this point in the history
Parameter not can be null (e.g., on scene close, if parameter not has not been set or not a singleton node), therefore it must be checked before its usage.

see Project-MONAI/MONAILabel#1300
  • Loading branch information
lassoan authored and jcfr committed Feb 21, 2023
1 parent b4090ea commit abd88fd
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1795,14 +1795,17 @@ void qMRMLSegmentEditorWidget::onMRMLSceneEndBatchProcessEvent()
{
return;
}
if (d->ParameterSetNode->GetSegmentationNode() != d->SegmentationNodeComboBox->currentNode())
{
this->setSegmentationNode(d->SegmentationNodeComboBox->currentNode());
}

if (d->ParameterSetNode->GetSourceVolumeNode() != d->SourceVolumeNodeComboBox->currentNode())
if (d->ParameterSetNode)
{
this->setSourceVolumeNode(d->SourceVolumeNodeComboBox->currentNode());
if (d->ParameterSetNode->GetSegmentationNode() != d->SegmentationNodeComboBox->currentNode())
{
this->setSegmentationNode(d->SegmentationNodeComboBox->currentNode());
}
if (d->ParameterSetNode->GetSourceVolumeNode() != d->SourceVolumeNodeComboBox->currentNode())
{
this->setSourceVolumeNode(d->SourceVolumeNodeComboBox->currentNode());
}
}

// force update (clear GUI if no node is selected anymore)
Expand Down Expand Up @@ -2264,7 +2267,7 @@ void qMRMLSegmentEditorWidget::onSwitchToSegmentations()
{
Q_D(qMRMLSegmentEditorWidget);

vtkMRMLSegmentationNode* segmentationNode = d->ParameterSetNode->GetSegmentationNode();
vtkMRMLSegmentationNode* segmentationNode = d->ParameterSetNode ? d->ParameterSetNode->GetSegmentationNode() : nullptr;
if (!segmentationNode)
{
return;
Expand Down Expand Up @@ -3434,7 +3437,7 @@ void qMRMLSegmentEditorWidget::onImportExportActionClicked()
{
Q_D(qMRMLSegmentEditorWidget);

vtkMRMLSegmentationNode* segmentationNode = d->ParameterSetNode->GetSegmentationNode();
vtkMRMLSegmentationNode* segmentationNode = d->ParameterSetNode ? d->ParameterSetNode->GetSegmentationNode() : nullptr;
if (!segmentationNode)
{
return;
Expand Down Expand Up @@ -3472,7 +3475,7 @@ void qMRMLSegmentEditorWidget::onExportToFilesActionClicked()
{
Q_D(qMRMLSegmentEditorWidget);

vtkMRMLSegmentationNode* segmentationNode = d->ParameterSetNode->GetSegmentationNode();
vtkMRMLSegmentationNode* segmentationNode = d->ParameterSetNode ? d->ParameterSetNode->GetSegmentationNode() : nullptr;
if (!segmentationNode)
{
return;
Expand Down

0 comments on commit abd88fd

Please sign in to comment.