From 27558c42bb8db177ce377089e8d82323bf50117c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eberhard=20Gr=C3=A4ther?= Date: Mon, 29 Jun 2020 01:05:53 +0200 Subject: [PATCH] ui: Fixed crash when changing tabs during animation (#1046) Changing tabs during animation triggers a hover leave event on the focused node, which moves the focus to the parent node if available. This parent node however is still the old node, and deleted after the graph transition animation finishes, which leaves a dangling pointer. closes #1021 --- src/lib_gui/qt/graphics/GraphFocusHandler.cpp | 23 ++++++++++++------- src/lib_gui/qt/view/QtGraphView.cpp | 2 ++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/lib_gui/qt/graphics/GraphFocusHandler.cpp b/src/lib_gui/qt/graphics/GraphFocusHandler.cpp index 7d25a04e..05a12858 100644 --- a/src/lib_gui/qt/graphics/GraphFocusHandler.cpp +++ b/src/lib_gui/qt/graphics/GraphFocusHandler.cpp @@ -91,19 +91,21 @@ void GraphFocusHandler::focusTokenId( void GraphFocusHandler::refocusNode( const std::list& newNodes, Id oldActiveTokenId, Id newActiveTokenId) { - const Id lastFocusId = m_lastFocusId; - clear(); - - if (lastFocusId && (lastFocusId == newActiveTokenId || oldActiveTokenId == newActiveTokenId)) + if (m_lastFocusId && (m_lastFocusId == newActiveTokenId || oldActiveTokenId == newActiveTokenId)) { - QtGraphNode* nodeToFocus = QtGraphNode::findNodeRecursive(newNodes, lastFocusId); + QtGraphNode* nodeToFocus = QtGraphNode::findNodeRecursive(newNodes, m_lastFocusId); if (nodeToFocus) { - m_focusNode = nodeToFocus; - m_lastFocusId = lastFocusId; - nodeToFocus->setIsFocused(true); + if (m_focusNode != nodeToFocus) + { + m_focusNode = nodeToFocus; + nodeToFocus->setIsFocused(true); + } + return; } } + + clear(); } void GraphFocusHandler::focusNext(Direction direction, bool navigateEdges) @@ -180,6 +182,11 @@ void GraphFocusHandler::focusNode(QtGraphNode* node) void GraphFocusHandler::defocusNode(QtGraphNode* node) { + if (node != m_focusNode) + { + return; + } + QtGraphNode* parent = node->getParent(); while (parent && !parent->isFocusable()) { diff --git a/src/lib_gui/qt/view/QtGraphView.cpp b/src/lib_gui/qt/view/QtGraphView.cpp index 51c5051a..93d8b6ce 100644 --- a/src/lib_gui/qt/view/QtGraphView.cpp +++ b/src/lib_gui/qt/view/QtGraphView.cpp @@ -937,6 +937,8 @@ void QtGraphView::updateTrailButtons() void QtGraphView::switchToNewGraphData() { + m_focusHandler.refocusNode(m_nodes, 0, 0); + m_oldGraph = m_graph; for (QtGraphNode* node: m_oldNodes)