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: ...@@ -681,6 +681,19 @@ private:
const QSet<QString> m_newSourceFiles; 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) QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo &newProjectInfo)
{ {
if (!newProjectInfo.isValid()) if (!newProjectInfo.isValid())
...@@ -738,14 +751,7 @@ QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo &newProjectIn ...@@ -738,14 +751,7 @@ QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo &newProjectIn
// Update Project/ProjectInfo and File/ProjectPart table // Update Project/ProjectInfo and File/ProjectPart table
m_dirty = true; m_dirty = true;
m_projectToProjectsInfo.insert(project, newProjectInfo); m_projectToProjectsInfo.insert(project, newProjectInfo);
m_fileToProjectParts.clear(); recalculateFileToProjectParts();
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);
}
}
}
} // Mutex scope } // Mutex scope
...@@ -823,6 +829,7 @@ void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project) ...@@ -823,6 +829,7 @@ void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project)
QMutexLocker locker(&m_projectMutex); QMutexLocker locker(&m_projectMutex);
m_dirty = true; m_dirty = true;
m_projectToProjectsInfo.remove(project); m_projectToProjectsInfo.remove(project);
recalculateFileToProjectParts();
} while (0); } while (0);
delayedGC(); delayedGC();
...@@ -841,6 +848,7 @@ void CppModelManager::onAboutToUnloadSession() ...@@ -841,6 +848,7 @@ void CppModelManager::onAboutToUnloadSession()
do { do {
QMutexLocker locker(&m_projectMutex); QMutexLocker locker(&m_projectMutex);
m_projectToProjectsInfo.clear(); m_projectToProjectsInfo.clear();
recalculateFileToProjectParts();
m_dirty = true; m_dirty = true;
} while (0); } while (0);
} }
......
...@@ -170,6 +170,8 @@ private slots: ...@@ -170,6 +170,8 @@ private slots:
private: private:
void delayedGC(); void delayedGC();
void recalculateFileToProjectParts();
void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot); void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot);
void removeFilesFromSnapshot(const QSet<QString> &removedFiles); void removeFilesFromSnapshot(const QSet<QString> &removedFiles);
void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo); 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