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
@@ -187,11 +187,13 @@ void DrawViewDetail::detailExec(TopoDS_Shape& shape, DrawViewPart* dvp, DrawView
|
||||
connectDetailWatcher =
|
||||
QObject::connect(&m_detailWatcher, &QFutureWatcherBase::finished, &m_detailWatcher,
|
||||
[this] { this->onMakeDetailFinished(); });
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
|
||||
m_detailFuture = QtConcurrent::run(this, &DrawViewDetail::makeDetailShape, shape, dvp, dvs);
|
||||
#else
|
||||
m_detailFuture = QtConcurrent::run(&DrawViewDetail::makeDetailShape, this, shape, dvp, dvs);
|
||||
#endif
|
||||
|
||||
// We create a lambda closure to hold a copy of shape.
|
||||
// This is important because this variable might be local to the calling
|
||||
// function and might get destructed before the parallel processing finishes.
|
||||
// TODO: What about dvp and dvs? Do they live past makeDetailShape?
|
||||
auto lambda = [this, shape, dvp, dvs]{this->makeDetailShape(shape, dvp, dvs);};
|
||||
m_detailFuture = QtConcurrent::run(std::move(lambda));
|
||||
m_detailWatcher.setFuture(m_detailFuture);
|
||||
waitingForDetail(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user