From bfd6040224b858a2abbade9477f43c235c51102e Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Wed, 19 Mar 2014 12:20:35 +0100 Subject: [PATCH] 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 --- .../projectexplorer/devicesupport/devicemanager.cpp | 12 +++++++++--- .../projectexplorer/devicesupport/devicemanager.h | 2 ++ src/plugins/projectexplorer/projectexplorer.cpp | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp index 7491333504b..e452a412b3f 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp +++ b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -81,11 +82,11 @@ DeviceManager *DeviceManagerPrivate::clonedInstance = 0; using namespace Internal; +DeviceManager *DeviceManager::m_instance = 0; DeviceManager *DeviceManager::instance() { - static DeviceManager instance; - return &instance; + return m_instance; } int DeviceManager::deviceCount() const @@ -337,14 +338,19 @@ const IDeviceFactory *DeviceManager::restoreFactory(const QVariantMap &map) 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())); + } } DeviceManager::~DeviceManager() { if (d->clonedInstance != this) delete d->writer; + if (m_instance == this) + m_instance = 0; delete d; } diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.h b/src/plugins/projectexplorer/devicesupport/devicemanager.h index 610925616f4..705be8ad59e 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanager.h +++ b/src/plugins/projectexplorer/devicesupport/devicemanager.h @@ -110,6 +110,8 @@ private: Internal::DeviceManagerPrivate * const d; + static DeviceManager *m_instance; + friend class Internal::DeviceManagerPrivate; friend class ProjectExplorerPlugin; }; diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 1b9968a7747..a9cc850148c 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -330,6 +330,8 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er return false; addObject(this); + addAutoReleasedObject(new DeviceManager); + // Add ToolChainFactories: #ifdef Q_OS_WIN addAutoReleasedObject(new WinDebugInterface);