From aa0e82e6c87bf9d26b00f0ddabd5ab81416449d1 Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Tue, 19 Oct 2010 07:26:26 +0200
Subject: [PATCH] QmlJS: Fix crash in debugger tooltips

Check that the node under cursor is indeed a UiObjectMember

Reviewed-by: Christiaan Janssen
Task-number: QTCREATORBUG-2760
---
 src/plugins/qmljsinspector/qmljsinspector.cpp | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/plugins/qmljsinspector/qmljsinspector.cpp b/src/plugins/qmljsinspector/qmljsinspector.cpp
index 7d00423d97c..997be7ee553 100644
--- a/src/plugins/qmljsinspector/qmljsinspector.cpp
+++ b/src/plugins/qmljsinspector/qmljsinspector.cpp
@@ -186,7 +186,7 @@ Debugger::QmlEngine *InspectorUi::debuggerEngine() const
 void InspectorUi::showDebuggerTooltip(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos)
 {
     Q_UNUSED(mousePos);
-    if (editor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) {
+    if (m_clientProxy && editor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) {
         QmlJSEditor::Internal::QmlJSTextEditor *qmlEditor = static_cast<QmlJSEditor::Internal::QmlJSTextEditor*>(editor->widget());
 
         QTextCursor tc(qmlEditor->document());
@@ -201,10 +201,16 @@ void InspectorUi::showDebuggerTooltip(const QPoint &mousePos, TextEditor::ITextE
         QmlJS::AST::Node *qmlNode = qmlEditor->semanticInfo().nodeUnderCursor(cursorPos);
         if (!qmlNode)
             return;
-        QmlJS::AST::Node *node = qmlEditor->semanticInfo().declaringMemberNoProperties(cursorPos);
-        if (!node)
-            return;
-        QDeclarativeDebugObjectReference ref = m_clientProxy->objectReferenceForLocation(node->uiObjectMemberCast()->firstSourceLocation().startLine, node->uiObjectMemberCast()->firstSourceLocation().startColumn);
+
+        QDeclarativeDebugObjectReference ref;
+        if (QmlJS::AST::Node *node
+                = qmlEditor->semanticInfo().declaringMemberNoProperties(cursorPos)) {
+            if (QmlJS::AST::UiObjectMember *objMember = node->uiObjectMemberCast()) {
+                ref = m_clientProxy->objectReferenceForLocation(
+                            objMember->firstSourceLocation().startLine,
+                            objMember->firstSourceLocation().startColumn);
+            }
+        }
 
         if (ref.debugId() == -1)
             return;
-- 
GitLab