ProjectTree: Fix crash when project has no rootProjectNode

Fix a crash that is triggered by a project returning to a state
where it has no rootProjectNode. This can happen when parsing fails
and Creator should fall back to displaying the project name and
its main project file as it does before any parsing had been done.

Unfortunately the hasNode function returned false in this case, so
the project model was never updated and the removed project nodes
stuck around, triggering a crash.

Change-Id: I7616e576773dc52fb6fdff39b9f0a7c7729eac71
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Tobias Hunger
2019-06-14 15:11:57 +02:00
committed by hjk
parent b9924e2b4b
commit e3690ad7ac

View File

@@ -393,9 +393,15 @@ void ProjectTree::applyTreeManager(FolderNode *folder)
bool ProjectTree::hasNode(const Node *node)
{
return Utils::contains(SessionManager::projects(), [node](const Project *p) {
return p && p->rootProjectNode() && (
p->containerNode() == node
|| p->rootProjectNode()->findNode([node](const Node *n) { return n == node; }));
if (!p)
return false;
if (p->containerNode() == node)
return true;
// When parsing fails we have a living container node but no rootProjectNode.
ProjectNode *pn = p->rootProjectNode();
if (!pn)
return false;
return pn->findNode([node](const Node *n) { return n == node; }) != nullptr;
});
}