# qMRMLColorTableNode causing Slicer to exit abnormally

**URL:** <https://discourse.slicer.org/t/qmrmlcolortablenode-causing-slicer-to-exit-abnormally/6726>\
**Category:** Support\
**Created:** [May 8, 2019, 12:48am UTC](https://discourse.slicer.org/t/qmrmlcolortablenode-causing-slicer-to-exit-abnormally/6726 "2019-05-08T00:48:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [May 8, 2019, 12:48am UTC](https://discourse.slicer.org/t/qmrmlcolortablenode-causing-slicer-to-exit-abnormally/6726/1 "2019-05-08T00:48:39Z")

</div>

I have been having problems using qMRMLColorTableComboBox and I can’t seem to figure it out. I’m using Slicer 4.10.1 and after creating the object and manipulating it as shown below, then upon closing the Slicer main window it will result in an exit abnormally message. Am I manipulating this in an incorrect way? Does an exit abnormally message usually indicate a specific issue with MRML widgets?

```python
class ColorTableTest():
  def __init__ (self):
    self.combobox = slicer.qMRMLColorTableComboBox()
    self.combobox.setMRMLScene(slicer.mrmlScene)

class_instance = ColorTableTest()
class_instance.combobox.setCurrentNodeID("vtkMRMLColorTableNodeGrey")

```

```auto
Python console user input: class ColorTableTest():
Python console user input: def __init__ (self):
Python console user input: self.combobox = slicer.qMRMLColorTableComboBox()
Python console user input: self.combobox.setMRMLScene(slicer.mrmlScene)
Python console user input: class_instance = ColorTableTest()
This function is deprecated. Use currentNodeID() instead
qMRMLNodeFactory::baseName failed: class name vtkMRMLColorTableNode not found
This function is deprecated. Use currentNodeID() instead
qMRMLNodeFactory::baseName failed: class name vtkMRMLColorTableNode not found
qMRMLNodeFactory::baseName failed: class name vtkMRMLColorTableNode not found
This function is deprecated. Use currentNodeID() instead
This function is deprecated. Use currentNodeID() instead
qMRMLNodeFactory::baseName failed: class name vtkMRMLColorTableNode not found
This function is deprecated. Use currentNodeID() instead
qMRMLNodeFactory::baseName failed: class name vtkMRMLColorTableNode not found
qMRMLNodeFactory::baseName failed: class name vtkMRMLColorTableNode not found
This function is deprecated. Use currentNodeID() instead
This function is deprecated. Use currentNodeID() instead
qMRMLNodeFactory::baseName failed: class name vtkMRMLColorTableNode not found
This function is deprecated. Use currentNodeID() instead
qMRMLNodeFactory::baseName failed: class name vtkMRMLColorTableNode not found
qMRMLNodeFactory::baseName failed: class name vtkMRMLColorTableNode not found
This function is deprecated. Use currentNodeID() instead
Python console user input: class_instance.combobox.setCurrentNodeID("vtkMRMLColorTableNodeGrey")
Switch to module: ""
Switch to module: ""
error: [C:/S4.10R/Slicer-build/bin/Release/SlicerApp-real.exe] exit abnormally - Report the problem.

```

---

<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:** [May 8, 2019, 1:19am UTC](https://discourse.slicer.org/t/qmrmlcolortablenode-causing-slicer-to-exit-abnormally/6726/2 "2019-05-08T01:19:31Z")

</div>

It is due to trying to update a widget (triggered by removing of nodes) when the GUI of the application has been already partially destroyed. You should be able to fix this by destroying the combobox or at least set its scene to None when your module widget is destroyed.

To avoid the deprecation warnings, use `class_instance.combobox.currentNodeID = "vtkMRMLColorTableNodeGrey"` instead of `setCurrentNodeID()`.

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [May 8, 2019, 3:24am UTC](https://discourse.slicer.org/t/qmrmlcolortablenode-causing-slicer-to-exit-abnormally/6726/3 "2019-05-08T03:24:52Z")

</div>

What’s the correct signal that I should be using?

Would I set it up as

```python
self.combobox.destroyed.connect( #method that clears scene or destroys object)

```

or is this too late and needs some signal before it gets destroyed?  
I’ve tried the above and it seems to still exit abnormally.

---

<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:** [May 8, 2019, 4:39am UTC](https://discourse.slicer.org/t/qmrmlcolortablenode-causing-slicer-to-exit-abnormally/6726/4 "2019-05-08T04:39:50Z")

</div>

Set scene to None in the destructor of the module widget class.

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [May 8, 2019, 2:22pm UTC](https://discourse.slicer.org/t/qmrmlcolortablenode-causing-slicer-to-exit-abnormally/6726/5 "2019-05-08T14:22:26Z")

</div>

In my test above adding the following seemed to prevent it from exiting abnormally (setting the scene to None was still causing exit abnormally with this test).

```python
class ColorTableTest():
  def __init__ (self):
    self.combobox = slicer.qMRMLColorTableComboBox()
    self.combobox.setMRMLScene(slicer.mrmlScene)
  def __del__ (self):
    self.combobox.delete()

```

However, in my real application, I’m still struggling to prevent the exit abnormally even with defining the destructor with this code in multiple areas too. Would I need to build a Slicer debug version and connect to process to nail this down further?

I’m able to use `slicer.qSlicerScalarVolumeDisplayWidget()` which includes a qMRMLColorTableComboBox and doesn’t cause an exit abnormally.

I attempted to try making a qMRMLNodeComboBox into a qMRMLColorTableComboBox, but I was also struggling to get this working as well.

---

<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:** [May 8, 2019, 3:45pm UTC](https://discourse.slicer.org/t/qmrmlcolortablenode-causing-slicer-to-exit-abnormally/6726/6 "2019-05-08T15:45:12Z")

</div>

Colors module logic destructor removes default color nodes from the scene. This happens very late and causes all these troubles. Color module should not pollute the scene with default color nodes anyway, so changing this should make the shutdown more robust. We’ve been planning to do this, but has not found a ND the time yet. It would be a backward-incompatible change, a good fit for current master branch, where we have many of those already.

To debug this, you certainly need a debug-mode build of Slicer.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [May 8, 2019, 5:41pm UTC](https://discourse.slicer.org/t/qmrmlcolortablenode-causing-slicer-to-exit-abnormally/6726/7 "2019-05-08T17:41:18Z")

</div>

In scripted module, you could override the `cleanup` method of the widget.

[https://github.com/Slicer/Slicer/blob/10bf184d585f7526b8083043da671b0970043a16/Base/Python/slicer/ScriptedLoadableModule.py#L99-L106](https://github.com/Slicer/Slicer/blob/10bf184d585f7526b8083043da671b0970043a16/Base/Python/slicer/ScriptedLoadableModule.py#L99-L106)

> What’s the correct signal that I should be using?

You could also directly observe the signal `qSlicerModuleManager::moduleAboutToBeUnloaded(QString)`, if module name being unloaded is `YourModuleName`, you would perform the cleanup and disconnect the signal.

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [May 8, 2019, 7:25pm UTC](https://discourse.slicer.org/t/qmrmlcolortablenode-causing-slicer-to-exit-abnormally/6726/8 "2019-05-08T19:25:52Z")

</div>

Thanks for the ideas!

I think I have found a solution that will work for my code.

Doing `slicer.app.aboutToQuit.connect(self.myCleanup)` appears to handle the `delete()` calls for the qMRMLColorTableComboBox widgets in an early enough time to prevent the exit abnormally.
