mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
197ea2b655
commit
8577b00cb7
5 changed files with 77 additions and 0 deletions
21
core/globals.cpp
Normal file
21
core/globals.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "globals.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
static std::vector<GlobalObjectBase *> global_objects;
|
||||
|
||||
void register_global_internal(GlobalObjectBase *o)
|
||||
{
|
||||
global_objects.push_back(o);
|
||||
}
|
||||
|
||||
void free_globals()
|
||||
{
|
||||
// We free the objects by hand, so that we can free them in reverse
|
||||
// order of creation. AFAIK, order-of-destruction is implementantion-defined
|
||||
// for std::vector<>.
|
||||
for (auto it = global_objects.rbegin(); it != global_objects.rend(); ++it)
|
||||
delete *it;
|
||||
global_objects.clear();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue