From 33c96800f0fbbe7b4576d25c79c768049e48f51a Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 27 Jul 2011 12:30:34 +0200 Subject: [PATCH] QmlJSDebugger: Fix crash when stopping debugger The destructor of QmlAdapter deletes the QDeclarativeDebugConnection, which in turn results in status changes to the QmLJSInspectorClient. This again leads to QmlAdapter::logServiceStatusChange() being called for the already half-destructed object ... break this change by guarding the pointer to QmlAdapter in QmlJSClientProxy. Change-Id: I7ae3d45b2146b4f02e3843375ecf276ae75d5ea0 Task-number: QTCREATORBUG-5500 Reviewed-on: http://codereview.qt.nokia.com/2276 Reviewed-by: Qt Sanity Bot Reviewed-by: Christiaan Janssen --- .../qmljsinspector/qmljsclientproxy.cpp | 21 ++++++++++++------- src/plugins/qmljsinspector/qmljsclientproxy.h | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/plugins/qmljsinspector/qmljsclientproxy.cpp b/src/plugins/qmljsinspector/qmljsclientproxy.cpp index e2257459d86..135dc58e9a6 100644 --- a/src/plugins/qmljsinspector/qmljsclientproxy.cpp +++ b/src/plugins/qmljsinspector/qmljsclientproxy.cpp @@ -65,11 +65,11 @@ ClientProxy::ClientProxy(Debugger::QmlAdapter *adapter, QObject *parent) void ClientProxy::connectToServer() { - m_engineClient = new QDeclarativeEngineDebug(m_adapter->connection(), this); + m_engineClient = new QDeclarativeEngineDebug(m_adapter.data()->connection(), this); connect(m_engineClient, SIGNAL(newObjects()), this, SLOT(newObjects())); - m_inspectorClient = new QmlJSInspectorClient(m_adapter->connection(), this); + m_inspectorClient = new QmlJSInspectorClient(m_adapter.data()->connection(), this); connect(m_inspectorClient, SIGNAL(connectedStatusChanged(QDeclarativeDebugClient::Status)), this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status))); @@ -96,7 +96,7 @@ void ClientProxy::connectToServer() connect(m_inspectorClient, SIGNAL(selectedColorChanged(QColor)), SIGNAL(selectedColorChanged(QColor))); connect(m_inspectorClient, SIGNAL(logActivity(QString,QString)), - m_adapter, SLOT(logServiceActivity(QString,QString))); + m_adapter.data(), SLOT(logServiceActivity(QString,QString))); updateConnected(); } @@ -108,7 +108,8 @@ void ClientProxy::clientStatusChanged(QDeclarativeDebugClient::Status status) serviceName = client->name(); } - m_adapter->logServiceStatusChange(serviceName, status); + if (m_adapter) + m_adapter.data()->logServiceStatusChange(serviceName, status); updateConnected(); } @@ -186,7 +187,8 @@ void ClientProxy::log(LogDirection direction, const QString &message) } msg += message; - m_adapter->logServiceActivity("QDeclarativeDebug", msg); + if (m_adapter) + m_adapter.data()->logServiceActivity("QDeclarativeDebug", msg); } QList QmlJSInspector::Internal::ClientProxy::rootObjectReference() const @@ -323,13 +325,16 @@ QDeclarativeDebugExpressionQuery *ClientProxy::queryExpressionResult(int objectD if (!isConnected()) return 0; - bool block = m_adapter->disableJsDebugging(true); + bool block = false; + if (m_adapter) + block = m_adapter.data()->disableJsDebugging(true); log(LogSend, QString("EVAL_EXPRESSION %1 %2").arg(QString::number(objectDebugId), expr)); QDeclarativeDebugExpressionQuery *query = m_engineClient->queryExpressionResult(objectDebugId, expr, m_engineClient); - m_adapter->disableJsDebugging(block); + if (m_adapter) + m_adapter.data()->disableJsDebugging(block); return query; } @@ -662,7 +667,7 @@ void ClientProxy::updateEngineList() Debugger::QmlAdapter *ClientProxy::qmlAdapter() const { - return m_adapter; + return m_adapter.data(); } bool ClientProxy::isConnected() const diff --git a/src/plugins/qmljsinspector/qmljsclientproxy.h b/src/plugins/qmljsinspector/qmljsclientproxy.h index 4513cbc52b6..02dbf9b549f 100644 --- a/src/plugins/qmljsinspector/qmljsclientproxy.h +++ b/src/plugins/qmljsinspector/qmljsclientproxy.h @@ -165,7 +165,7 @@ private: Q_DISABLE_COPY(ClientProxy) void buildDebugIdHashRecursive(const QDeclarativeDebugObjectReference &ref); - Debugger::QmlAdapter *m_adapter; + QWeakPointer m_adapter; QDeclarativeEngineDebug *m_engineClient; QmlJSInspectorClient *m_inspectorClient;