core: add class that collects global objects to be deleted on exit

We have a prevailing problem with global QObjects defined as
static global variables. These get destructed after main()
exits, which means that the QApplication object does not
exist anymore. This more often than not leads to crashes.

In a quick search I didn't find a mechanism to register
objects for deletion with QApplication. Therefore, let's
do our own list of global objects that get destructed
before destroying the QApplication.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-03-12 18:30:23 +01:00 committed by Dirk Hohndel
parent 197ea2b655
commit 8577b00cb7
5 changed files with 77 additions and 0 deletions

View file

@ -8,6 +8,7 @@
#endif
#include "stats/statsview.h"
#include "core/globals.h"
#include "core/qt-gui.h"
#include "core/settings/qPref.h"
#include "core/ssrf.h"
@ -67,6 +68,7 @@ void exit_ui()
#ifndef SUBSURFACE_MOBILE
delete MainWindow::instance();
#endif // SUBSURFACE_MOBILE
free_globals();
free((void *)existing_filename);
}