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
This commit is contained in:
@@ -91,19 +91,21 @@ void GraphFocusHandler::focusTokenId(
|
||||
void GraphFocusHandler::refocusNode(
|
||||
const std::list<QtGraphNode*>& 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())
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user