# vtkMRMLSubjectHierarchyNode causes Slicer to crash during surgical plan

**URL:** <https://discourse.slicer.org/t/vtkmrmlsubjecthierarchynode-causes-slicer-to-crash-during-surgical-plan/25852>\
**Category:** Support\
**Created:** [October 23, 2022, 11:30pm UTC](https://discourse.slicer.org/t/vtkmrmlsubjecthierarchynode-causes-slicer-to-crash-during-surgical-plan/25852 "2022-10-23T23:30:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [October 23, 2022, 11:30pm UTC](https://discourse.slicer.org/t/vtkmrmlsubjecthierarchynode-causes-slicer-to-crash-during-surgical-plan/25852/1 "2022-10-23T23:30:52Z")

</div>

Hi. Thank you for the hardwork on Slicer development!

I have developed a very nice feature I would like to integrate to the main branch of [GitHub - SlicerIGT/SlicerBoneReconstructionPlanner: 3D Slicer module for planning mandible reconstruction surgery using fibula flap](https://github.com/SlicerIGT/SlicerBoneReconstructionPlanner)

This module handles tens of objects in a handful of folders that are created and deleted during the workflow. Till now it was stable enough. But now it is not, one folder with lots of items and subfolders is not visible on the subject hierarchie till I press right click on some folder visibility button, then it appears but Slicer shows the processing mouse cursor animation and then it crashes (sometimes). Other times it crashes when I start processing but not reliably (this involves creation and deletion of folders).

Hope you can help.

Mauro

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 24, 2022, 2:23am UTC](https://discourse.slicer.org/t/vtkmrmlsubjecthierarchynode-causes-slicer-to-crash-during-surgical-plan/25852/2 "2022-10-24T02:23:45Z")

</div>

> [@mau\_igna\_06](#):
>
> Till now it was stable enough. But now it is not

Which Slicer versions do you mean by “till now” and “now”?

To investigate, we need to be able to reproduce the issue. Ideally, a script that we can copy-paste into the Python console.

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [October 25, 2022, 1:42pm UTC](https://discourse.slicer.org/t/vtkmrmlsubjecthierarchynode-causes-slicer-to-crash-during-surgical-plan/25852/3 "2022-10-25T13:42:32Z")

</div>

Hi

> [@lassoan](#):
>
> Which Slicer versions do you mean by “till now” and “now”?

I mean today’s preview release by “now” and “till now”.

> To investigate, we need to be able to reproduce the issue. Ideally, a script that we can copy-paste into the Python console.

On a virtual surgical plan, BRP creates the hierarchy below when clicking the “Update fibula planes over the fibula line, bone pieces and transform them to the mandible” button:

```auto
BoneReconstructionPlanner/
  Mandible reconstruction/
    LotsOfNodesAndSubfolders 
 Inverse mandible reconstruction/ <-- this folder visibility is set to hidden while creating it
    LotsOfNodesAndSubfolders

```

There are two problems with the image below:

- 
  1. The “Inverse mandible reconstruction” folder doesn’t appear on the qMRMLSubjectHierarchyTreeView although it has been created.

- 
  1. The orange mandible that appears over the fibula on the lower 3D view is inside the “Inverse mandible reconstruction” folder (and it should be hidden because its parent folder is hidden)  
 ![Screenshot from 2022-10-25 10-03-55](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/e/be7a190b017f4afcff91988babca20ab057bdb4e.jpeg)

When I click the eye icon on qMRMLSubjectHierarchyTreeView of “Mandible reconstruction” the “Inverse mandible reconstruction” folder appears:

 ![Screenshot from 2022-10-25 10-04-14](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/7/07d54d79ef6b893631c26f5e483eb93dc8e21a88.jpeg)

If I click on the eye icon of the “Inverse mandible reconstruction” folder (once or twice) Slicer crashes.

* * *

Here is a Slicer scene where you can quickly make Slicer crash:  
[https://1drv.ms/u/s!AgpRvclrLSCegWlpmdL1L8s9BXrg?e=1btqGb](https://1drv.ms/u/s!AgpRvclrLSCegWlpmdL1L8s9BXrg?e=1btqGb)

You need to install BoneReconstructionPlanner extension, then in “application settings”-\>“modules” replace the BRP folder path by the module path inside this branch of BRP, load the scene I provided, switch to BoneReconstructionPlanner module and do the button-clicks I explained at the beginning.

Thank you, hope you can help

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [October 26, 2022, 6:35pm UTC](https://discourse.slicer.org/t/vtkmrmlsubjecthierarchynode-causes-slicer-to-crash-during-surgical-plan/25852/4 "2022-10-26T18:35:39Z")

</div>

The solution was simple though, just replace the last line of this:

```auto
      inverseMandibleReconstructionFolder = shNode.CreateFolderItem(parentItemID,"Inverse mandible reconstruction")
      pluginHandler = slicer.qSlicerSubjectHierarchyPluginHandler().instance()
      folderPlugin = pluginHandler.pluginByName("Folder")
      folderPlugin.setDisplayVisibility(inverseMandibleReconstructionFolder, 0)

```

by this:

```auto
      qt.QTimer.singleShot(0, lambda: folderPlugin.setDisplayVisibility(inverseMandibleReconstructionFolder, 0))

```

May be it should be clarified [here](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#manipulate-subject-hierarchy-item) that you should use a timer if you are not on the python console (for more context see [this link](https://github.com/SlicerIGT/SlicerBoneReconstructionPlanner/commit/b58d3f961c5e32c2ed764b6c83a8943661697418#diff-35cef951fd2ef7675f25d45a8e5933c707de10ecb4835702b2b1b4c587fc87d8L231)).

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [October 26, 2022, 10:09pm UTC](https://discourse.slicer.org/t/vtkmrmlsubjecthierarchynode-causes-slicer-to-crash-during-surgical-plan/25852/5 "2022-10-26T22:09:12Z")

</div>

There is a useful bug:

> If you delete and create a folder with the same name Slicer remembers if it was visible or not before you would have deleted it

This is useful for BRP because you can select on the treeview if you want to see the folder of “Mandible reconstruction” or “Inverse mandible reconstruction” and then after updating the virtual surgical plan it doesn’t autotoggle back to “Mandible reconstruction” folder

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 27, 2022, 3:56am UTC](https://discourse.slicer.org/t/vtkmrmlsubjecthierarchynode-causes-slicer-to-crash-during-surgical-plan/25852/6 "2022-10-27T03:56:46Z")

</div>

It should be safe to call `folderPlugin.setDisplayVisibility(inverseMandibleReconstructionFolder, 0)` right after creating the folder. I could not reproduce any issue with calling this method immediately.

Would you be able to come up with a minimal example that demonstrates how calling `setDisplayVisibility` immediately causes any issue?
