mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 13:09:52 +02:00
change singleton approach to not require delete
This commit is contained in:
parent
e03c7be5ef
commit
81bff60645
3 changed files with 3 additions and 25 deletions
|
@ -360,7 +360,6 @@ Application::~Application() {
|
||||||
|
|
||||||
VoxelTreeElement::removeDeleteHook(&_voxels); // we don't need to do this processing on shutdown
|
VoxelTreeElement::removeDeleteHook(&_voxels); // we don't need to do this processing on shutdown
|
||||||
Menu::getInstance()->deleteLater();
|
Menu::getInstance()->deleteLater();
|
||||||
MenuScriptingInterface::deleteLaterIfExists();
|
|
||||||
|
|
||||||
_myAvatar = NULL;
|
_myAvatar = NULL;
|
||||||
|
|
||||||
|
|
|
@ -11,26 +11,9 @@
|
||||||
#include "MenuScriptingInterface.h"
|
#include "MenuScriptingInterface.h"
|
||||||
|
|
||||||
|
|
||||||
MenuScriptingInterface* MenuScriptingInterface::_instance = NULL;
|
|
||||||
QMutex MenuScriptingInterface::_instanceMutex;
|
|
||||||
|
|
||||||
MenuScriptingInterface* MenuScriptingInterface::getInstance() {
|
MenuScriptingInterface* MenuScriptingInterface::getInstance() {
|
||||||
// lock the menu instance mutex to make sure we don't race and create two menus and crash
|
static MenuScriptingInterface sharedInstance;
|
||||||
_instanceMutex.lock();
|
return &sharedInstance;
|
||||||
if (!_instance) {
|
|
||||||
_instance = new MenuScriptingInterface();
|
|
||||||
}
|
|
||||||
_instanceMutex.unlock();
|
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuScriptingInterface::deleteLaterIfExists() {
|
|
||||||
_instanceMutex.lock();
|
|
||||||
if (_instance) {
|
|
||||||
_instance->deleteLater();
|
|
||||||
_instance = NULL;
|
|
||||||
}
|
|
||||||
_instanceMutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuScriptingInterface::menuItemTriggered() {
|
void MenuScriptingInterface::menuItemTriggered() {
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#ifndef __hifi__MenuScriptingInterface__
|
#ifndef __hifi__MenuScriptingInterface__
|
||||||
#define __hifi__MenuScriptingInterface__
|
#define __hifi__MenuScriptingInterface__
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
@ -21,7 +22,6 @@ class MenuScriptingInterface : public QObject {
|
||||||
MenuScriptingInterface() { };
|
MenuScriptingInterface() { };
|
||||||
public:
|
public:
|
||||||
static MenuScriptingInterface* getInstance();
|
static MenuScriptingInterface* getInstance();
|
||||||
static void deleteLaterIfExists();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
friend class Menu;
|
friend class Menu;
|
||||||
|
@ -44,10 +44,6 @@ public slots:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void menuItemEvent(const QString& menuItem);
|
void menuItemEvent(const QString& menuItem);
|
||||||
|
|
||||||
private:
|
|
||||||
static QMutex _instanceMutex;
|
|
||||||
static MenuScriptingInterface* _instance;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__MenuScriptingInterface__) */
|
#endif /* defined(__hifi__MenuScriptingInterface__) */
|
||||||
|
|
Loading…
Reference in a new issue