Slicer fails on startup in debug mode if temporary folder is set to empty

I’m working on an loadable application where I’m changing the temporary directory path to work in my own application directory. I’m changing the directory path by using qSlicerCoreApplication::application->setTemporaryPath(d->folderPath) and I’m using it to create Dicom database in that directory. The “d->folderPath” variable is the temporary directory selected by user using QFileDialog.
It has been working fine for sometime but recently I got an error and slicer fails to load at startup. The error is:

“[100%] Built target qSlicerDAFSModuleGenericCxxTests
ASSERT: “!d->TempDirectory.isEmpty()” in file /home/simtiaz/Myproject/Slicer-build/slicersources-src/Base/QTCLI/qSlicerCLIModule.cxx, line 78”.

I’m not sure why this error is generated and why slicer crashes on startup but it happens randomly after some amount of tries. I think potential issue is sometimes slicer exits abnormally and when it starts, it can not find temporary directory path. I have to rebuild slicer to fix this issue. Is changing temporary path causing this issue?

Q_ASSERT(!d->TempDirectory.isEmpty()); is just a debug-mode assertion, warning you that the temporary folder is not set (or set to an invalid empty string) by the time the module is being set up. Assertions supposed to work like this - crashing the application in debug mode to make sure developer notice them. In general we prefer replacing them with logging a warning message, so if you want to change this then send us a pull request.

Nevertheless, you need to fix the root cause of the error, which is most likely that you set the temp folder to an empty (or maybe invalid?) folder somewhere. Since you cannot achieve anything with setting the temporary folder to a particular location (you can only break things by not setting it to a writeable folder), I would suggest not to mess with it. Leave it at the default.

If you want to create the DICOM database somewhere else then just create it somewhere else by specifying the desired location: DICOMUtils.TemporaryDICOMDatabase(mytempfolder). But the fact that you actually care about where this folder resides indicates that is actually not a temporary database, so probably you should just use the application’s default DICOM database.

Hi @Lassoan,
Thanks for your response, I looked into DICOMUtils.py and see there is option to set absolute path as tempDatabaseDir. Before I was just giving directory name and changing temporary directory path. I should have checked this option earlier as this way I don’t need to change slicer’s default temporary path. Let me test this and see if I run into any issues.
I’m not sure if this should be warning as it could affect other modules or if any invalid path set or no path set as per your reasoning, but is there any way to find root cause to it. I did try setting temporary path using slicer.app.temporaryPath= “Path” in .slicerrc.py and re-run slicer but issue persisted.

Thanks for the support.
Regards

I would recommend to set a valid temporary path in the GUI (menu: Edit / Application settings / Modules / Temporary directory) and then don’t modify it from scripts.

Actually the slicer crashes on initialization screen so there is no way to go to toolbar options. If there is any external file or option which sets the temporaryPath, that could be tested. I have rebuilt slicer and changed my code, now it is working fine but I’ll be testing it more to see if this issue comes again, I doubt it will. Thanks for the help, closing this topic.

Temporary path is stored in Slicer.ini settings file, you can view/change it by editing that file.

1 Like

Yes, I checked and the temporary path field was empty in Slicer.ini file. Adding temporary path has fixed the issue. Thanks

1 Like