From a2252ba7b3942bbafbbb8f4db144f2cfbf0787ab Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Sun, 22 Jan 2017 16:48:15 +0100 Subject: Fix case when async PathItem goes down before finish Marking the work orphaned (to be ignored) is sufficient since runnables exist independently of the renderer or item instances. (even if the lambda executes after the entire Quick infra is gone, we are still fine, as long as we bail out in time and do not dereference the captured this) Change-Id: I0cfb09aaa8b363191ff576b17a88bb7c1c38f3ad Reviewed-by: Andy Nichols --- src/quick/items/qquickpathitemgenericrenderer.cpp | 12 ++++++++++++ src/quick/items/qquickpathitemgenericrenderer_p.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/quick/items/qquickpathitemgenericrenderer.cpp b/src/quick/items/qquickpathitemgenericrenderer.cpp index 367fac985e..e36654ad0c 100644 --- a/src/quick/items/qquickpathitemgenericrenderer.cpp +++ b/src/quick/items/qquickpathitemgenericrenderer.cpp @@ -104,6 +104,16 @@ void QQuickPathItemGenericStrokeFillNode::activateMaterial(Material m) setMaterial(m_material); } +QQuickPathItemGenericRenderer::~QQuickPathItemGenericRenderer() +{ + for (VisualPathData &d : m_vp) { + if (d.pendingFill) + d.pendingFill->orphaned = true; + if (d.pendingStroke) + d.pendingStroke->orphaned = true; + } +} + // sync, and so triangulation too, happens on the gui thread // - except when async is set, in which case triangulation is moved to worker threads @@ -263,6 +273,8 @@ void QQuickPathItemGenericRenderer::endSync(bool async) // Unlikely in practice but in theory m_vp could be // resized. Therefore, capture 'i' instead of 'd'. QObject::connect(r, &QQuickPathItemFillRunnable::done, qApp, [this, i](QQuickPathItemFillRunnable *r) { + // Bail out when orphaned (meaning either another run was + // started after this one, or the renderer got destroyed). if (!r->orphaned && i < m_vp.count()) { VisualPathData &d(m_vp[i]); d.fillVertices = r->fillVertices; diff --git a/src/quick/items/qquickpathitemgenericrenderer_p.h b/src/quick/items/qquickpathitemgenericrenderer_p.h index 17c1f73310..ca05492841 100644 --- a/src/quick/items/qquickpathitemgenericrenderer_p.h +++ b/src/quick/items/qquickpathitemgenericrenderer_p.h @@ -81,6 +81,7 @@ public: m_accDirty(0), m_asyncCallback(nullptr) { } + ~QQuickPathItemGenericRenderer(); void beginSync(int totalCount) override; void setPath(int index, const QQuickPath *path) override; -- cgit v1.2.3