SegFault with in `~qSlicerApplicationPrivate` only with SlicerCAT


When I updated the Slicer commit in my SlicerCAT I started to get Segmentation Fault in qSlicerApplicationPrivate destructor

This happens only with SlicerCAT (clean Slicer app works fine) even when all the modules are disabled ie SlicerCAT is launched with --disable-modules

Here are the steps that leads to this:

  1. launch SlicerCAT
  2. open Application Settings
  3. close Application Settings
  4. close SlicerCAT

It seems that this->SettingsDialog is already somehow unavailable by the time setting setParent(nullptr)
I’ve tried to rebuild it, debug but without success. Even though the idea behind creating/deleting SettingsDialog is pretty clear.

If somebody uses SlicerCAT with recent commits (after 26 february) I would appreciate for testing that.

Oh it seems I understand the root of a problem:

At first Settings has no parent at the initilization time

When we click on Application Settings the Settings object gets MainWindow parent. That means MainWindow destructor will delete Settings.

Then in ~qSlicerApplicationPrivate() destructor we are trying to set Settings parent to nullptr and explicitely delete Settings.

But what if ~MainWindow destructor is called before ~qSlicerApplicationPrivate destructor? Then in ~qSlicerApplicationPrivate we will try to access deleted Settings object.

I added cout to these destructors to see who is deleted first and the output is:

$ ./Colada --disable-modules
QXcbConnection: XCB error: 3 (BadWindow), sequence: 1157, resource id: 14779307, major code: 40 (TranslateCoords), minor code: 0
MainWindow destructor is called
Switch to module:  ""
qSlicerApplicationPrivate destructor is called
error: [~/Documents/Colada/d/Slicer-build/bin/./ColadaApp-real] exit abnormally - Report the problem.

That means in my SlicerCAT (I suspect in others too) ~MainWindow is deleted first so there is no need to explicitely delete Settings in ~qSlicerApplicationPrivate destructor.

Please take a look at this

The same issue is solved for the Python console, by using a QPointer. It would be great if you could submit a pull request that passes the ownership of the settings dialog similarly to how it is done for the Python console.

1 Like

Could please show where can I find Python console QPointer solution?
I have an idea how to solve this with QPointer but don’t know anything about python console implementation yet.

Search for QPointer and PythonConsole in the source and header files of the Slicer application classes.

1 Like

The PR is ready

1 Like