DeviceManager: Fix lifecycle

This prevents a crash when the DeviceManager tries to bring up a UI during
its destruction.

This happens in the same situation as described in QTCREATORBUG-11712,
which actually describes the same problem in BlackBerryConfigurationManager.

Change-Id: I06f134ffa282a281c81fd022c5a2f52fb5dddb56
Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
This commit is contained in:
Tobias Hunger
2014-03-19 12:20:35 +01:00
parent 99c38093de
commit bfd6040224
3 changed files with 13 additions and 3 deletions

View File

@@ -34,6 +34,7 @@
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <utils/qtcassert.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/persistentsettings.h> #include <utils/persistentsettings.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -81,11 +82,11 @@ DeviceManager *DeviceManagerPrivate::clonedInstance = 0;
using namespace Internal; using namespace Internal;
DeviceManager *DeviceManager::m_instance = 0;
DeviceManager *DeviceManager::instance() DeviceManager *DeviceManager::instance()
{ {
static DeviceManager instance; return m_instance;
return &instance;
} }
int DeviceManager::deviceCount() const int DeviceManager::deviceCount() const
@@ -337,14 +338,19 @@ const IDeviceFactory *DeviceManager::restoreFactory(const QVariantMap &map)
DeviceManager::DeviceManager(bool isInstance) : d(new DeviceManagerPrivate) DeviceManager::DeviceManager(bool isInstance) : d(new DeviceManagerPrivate)
{ {
if (isInstance) if (isInstance) {
QTC_ASSERT(!m_instance, return);
m_instance = this;
connect(Core::ICore::instance(), SIGNAL(saveSettingsRequested()), SLOT(save())); connect(Core::ICore::instance(), SIGNAL(saveSettingsRequested()), SLOT(save()));
} }
}
DeviceManager::~DeviceManager() DeviceManager::~DeviceManager()
{ {
if (d->clonedInstance != this) if (d->clonedInstance != this)
delete d->writer; delete d->writer;
if (m_instance == this)
m_instance = 0;
delete d; delete d;
} }

View File

@@ -110,6 +110,8 @@ private:
Internal::DeviceManagerPrivate * const d; Internal::DeviceManagerPrivate * const d;
static DeviceManager *m_instance;
friend class Internal::DeviceManagerPrivate; friend class Internal::DeviceManagerPrivate;
friend class ProjectExplorerPlugin; friend class ProjectExplorerPlugin;
}; };

View File

@@ -330,6 +330,8 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
return false; return false;
addObject(this); addObject(this);
addAutoReleasedObject(new DeviceManager);
// Add ToolChainFactories: // Add ToolChainFactories:
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
addAutoReleasedObject(new WinDebugInterface); addAutoReleasedObject(new WinDebugInterface);