Commit 90130f45 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools: Tests: Fix crash in test_modelmanager_gc_if_last_cppeditor_closed

The project that was referenced at cppeditor.cpp:711 was already
deleted. CppModelManager::m_fileToProjectParts contained outdated
information. Now it is updated if a project is closed.

Exposed by commit d411c076.

Change-Id: I6fee93a02c72a045dd44a05723ab39a1eeec616e
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 802b67ff
......@@ -681,6 +681,19 @@ private:
const QSet<QString> m_newSourceFiles;
};
/// Make sure that m_projectMutex is locked when calling this.
void CppModelManager::recalculateFileToProjectParts()
{
m_fileToProjectParts.clear();
foreach (const ProjectInfo &projectInfo, m_projectToProjectsInfo) {
foreach (const ProjectPart::Ptr &projectPart, projectInfo.projectParts()) {
foreach (const ProjectFile &cxxFile, projectPart->files) {
m_fileToProjectParts[cxxFile.path].append(projectPart);
}
}
}
}
QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo &newProjectInfo)
{
if (!newProjectInfo.isValid())
......@@ -738,14 +751,7 @@ QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo &newProjectIn
// Update Project/ProjectInfo and File/ProjectPart table
m_dirty = true;
m_projectToProjectsInfo.insert(project, newProjectInfo);
m_fileToProjectParts.clear();
foreach (const ProjectInfo &projectInfo, m_projectToProjectsInfo) {
foreach (const ProjectPart::Ptr &projectPart, projectInfo.projectParts()) {
foreach (const ProjectFile &cxxFile, projectPart->files) {
m_fileToProjectParts[cxxFile.path].append(projectPart);
}
}
}
recalculateFileToProjectParts();
} // Mutex scope
......@@ -823,6 +829,7 @@ void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project)
QMutexLocker locker(&m_projectMutex);
m_dirty = true;
m_projectToProjectsInfo.remove(project);
recalculateFileToProjectParts();
} while (0);
delayedGC();
......@@ -841,6 +848,7 @@ void CppModelManager::onAboutToUnloadSession()
do {
QMutexLocker locker(&m_projectMutex);
m_projectToProjectsInfo.clear();
recalculateFileToProjectParts();
m_dirty = true;
} while (0);
}
......
......@@ -170,6 +170,8 @@ private slots:
private:
void delayedGC();
void recalculateFileToProjectParts();
void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot);
void removeFilesFromSnapshot(const QSet<QString> &removedFiles);
void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment