change singleton approach to not require delete

This commit is contained in:
ZappoMan 2014-02-25 14:53:57 -08:00
parent e03c7be5ef
commit 81bff60645
3 changed files with 3 additions and 25 deletions

View file

@ -360,7 +360,6 @@ Application::~Application() {
VoxelTreeElement::removeDeleteHook(&_voxels); // we don't need to do this processing on shutdown
Menu::getInstance()->deleteLater();
MenuScriptingInterface::deleteLaterIfExists();
_myAvatar = NULL;

View file

@ -11,26 +11,9 @@
#include "MenuScriptingInterface.h"
MenuScriptingInterface* MenuScriptingInterface::_instance = NULL;
QMutex MenuScriptingInterface::_instanceMutex;
MenuScriptingInterface* MenuScriptingInterface::getInstance() {
// lock the menu instance mutex to make sure we don't race and create two menus and crash
_instanceMutex.lock();
if (!_instance) {
_instance = new MenuScriptingInterface();
}
_instanceMutex.unlock();
return _instance;
}
void MenuScriptingInterface::deleteLaterIfExists() {
_instanceMutex.lock();
if (_instance) {
_instance->deleteLater();
_instance = NULL;
}
_instanceMutex.unlock();
static MenuScriptingInterface sharedInstance;
return &sharedInstance;
}
void MenuScriptingInterface::menuItemTriggered() {

View file

@ -9,6 +9,7 @@
#ifndef __hifi__MenuScriptingInterface__
#define __hifi__MenuScriptingInterface__
#include <QDebug>
#include <QMutex>
#include <QObject>
#include <QString>
@ -21,7 +22,6 @@ class MenuScriptingInterface : public QObject {
MenuScriptingInterface() { };
public:
static MenuScriptingInterface* getInstance();
static void deleteLaterIfExists();
private slots:
friend class Menu;
@ -44,10 +44,6 @@ public slots:
signals:
void menuItemEvent(const QString& menuItem);
private:
static QMutex _instanceMutex;
static MenuScriptingInterface* _instance;
};
#endif /* defined(__hifi__MenuScriptingInterface__) */