TechDraw: creates closure for concurrent thread context.
We use a lambda function with a copy of variables that might be destructed in the original calling thread, possibly producing dangling references. See: https://forum.freecad.org/viewtopic.php?t=81260
This commit is contained in:
committed by
WandererFan
parent
c2bf9efc7d
commit
695a314229
@@ -462,11 +462,12 @@ void DrawViewSection::sectionExec(TopoDS_Shape& baseShape)
|
||||
QObject::connect(&m_cutWatcher, &QFutureWatcherBase::finished, &m_cutWatcher, [this] {
|
||||
this->onSectionCutFinished();
|
||||
});
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
m_cutFuture = QtConcurrent::run(this, &DrawViewSection::makeSectionCut, baseShape);
|
||||
#else
|
||||
m_cutFuture = QtConcurrent::run(&DrawViewSection::makeSectionCut, this, baseShape);
|
||||
#endif
|
||||
|
||||
// We create a lambda closure to hold a copy of baseShape.
|
||||
// This is important because this variable might be local to the calling
|
||||
// function and might get destructed before the parallel processing finishes.
|
||||
auto lambda = [this, baseShape]{this->makeSectionCut(baseShape);};
|
||||
m_cutFuture = QtConcurrent::run(std::move(lambda));
|
||||
m_cutWatcher.setFuture(m_cutFuture);
|
||||
waitingForCut(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user