forked from qt-creator/qt-creator
CMake: fix crash on project close during active file system scanning
TreeScanner uses callbacks that can refers to the destroyed objectes when project closing. Found scenario: 1. Open big CMake-based project (CLang/LLVM good choose). 2. Until file system scanning finished switch to another session. Change-Id: Ia0f55f38aea6a9d07ca81aee6c9e9c5662d74f3a Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
committed by
Tobias Hunger
parent
336adaa604
commit
bc46ba11ee
@@ -128,6 +128,11 @@ CMakeProject::CMakeProject(CMakeManager *manager, const FileName &fileName)
|
||||
|
||||
CMakeProject::~CMakeProject()
|
||||
{
|
||||
if (!m_treeScanner.isFinished()) {
|
||||
auto future = m_treeScanner.future();
|
||||
future.cancel();
|
||||
future.waitForFinished();
|
||||
}
|
||||
setRootProjectNode(nullptr);
|
||||
m_codeModelFuture.cancel();
|
||||
qDeleteAll(m_extraCompilers);
|
||||
|
||||
@@ -50,6 +50,14 @@ TreeScanner::TreeScanner(QObject *parent) : QObject(parent)
|
||||
connect(&m_futureWatcher, &FutureWatcher::finished, this, &TreeScanner::finished);
|
||||
}
|
||||
|
||||
TreeScanner::~TreeScanner()
|
||||
{
|
||||
if (!m_futureWatcher.isFinished()) {
|
||||
m_futureWatcher.cancel();
|
||||
m_futureWatcher.waitForFinished();
|
||||
}
|
||||
}
|
||||
|
||||
bool TreeScanner::asyncScanForFiles(const Utils::FileName &directory)
|
||||
{
|
||||
if (!m_futureWatcher.isFinished())
|
||||
|
||||
@@ -53,6 +53,7 @@ public:
|
||||
using FileTypeFactory = std::function<ProjectExplorer::FileType(const Utils::MimeType &, const Utils::FileName &)>;
|
||||
|
||||
explicit TreeScanner(QObject *parent = nullptr);
|
||||
~TreeScanner();
|
||||
|
||||
// Start scanning in given directory
|
||||
bool asyncScanForFiles(const Utils::FileName& directory);
|
||||
|
||||
Reference in New Issue
Block a user