From dae3b06885cc10b5a728720f9424149848c797f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 7 Nov 2016 02:28:18 +0100 Subject: [PATCH] NOISSUE fix horrible globals crash FIXME: remove all globals. --- api/logic/Env.cpp | 15 +++++++++++++-- api/logic/Env.h | 1 + application/MultiMC.cpp | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/api/logic/Env.cpp b/api/logic/Env.cpp index b769c9c4..a6341ebd 100644 --- a/api/logic/Env.cpp +++ b/api/logic/Env.cpp @@ -22,6 +22,8 @@ public: QString m_wonkoRootUrl; }; +static Env * instance; + /* * The *NEW* global rat nest of an object. Handle with care. */ @@ -38,8 +40,17 @@ Env::~Env() Env& Env::Env::getInstance() { - static Env instance; - return instance; + if(!instance) + { + instance = new Env(); + } + return *instance; +} + +void Env::dispose() +{ + delete instance; + instance = nullptr; } shared_qobject_ptr< HttpMetaCache > Env::metacache() diff --git a/api/logic/Env.h b/api/logic/Env.h index 989b4f3c..c72447ce 100644 --- a/api/logic/Env.h +++ b/api/logic/Env.h @@ -27,6 +27,7 @@ private: class Private; Env(); ~Env(); + static void dispose(); public: static Env& getInstance(); diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 0ca12adb..334c51fc 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -319,6 +319,7 @@ MultiMC::~MultiMC() } #endif shutdownLogger(); + Env::dispose(); } void MultiMC::messageReceived(const QString& message)