diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2022-11-10 14:35:01 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2022-11-11 12:07:42 +0100 |
commit | e52efc3defe102a55b45b013764ba1bae1fe5a1b (patch) | |
tree | e58cf56af299a73578092e9a4eb61a9ea975afae /src | |
parent | 920745223d1c1ff401e3083327fcd88d8461ebc0 (diff) |
Handle missing stops gracefully in Shape gradients
Fixes: QTBUG-108298
Pick-to: 6.4 6.2 5.15
Change-Id: Ib6e004a1518aec4c786c3aeebcd74e6cb11f45ef
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quickshapes/qquickshape.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/quickshapes/qquickshape.cpp b/src/quickshapes/qquickshape.cpp index 588a207e88..cdf20f8f83 100644 --- a/src/quickshapes/qquickshape.cpp +++ b/src/quickshapes/qquickshape.cpp @@ -1438,6 +1438,7 @@ static void generateGradientColorTable(const QQuickShapeGradientCacheKey &gradie { int pos = 0; const QGradientStops &s = gradient.stops; + Q_ASSERT(!s.isEmpty()); const bool colorInterpolation = true; uint alpha = qRound(opacity * 256); @@ -1475,8 +1476,6 @@ static void generateGradientColorTable(const QQuickShapeGradientCacheKey &gradie current_color = next_color; } - Q_ASSERT(s.size() > 0); - uint last_color = ARGB2RGBA(qPremultiply(ARGB_COMBINE_ALPHA(s[sLast].second.rgba(), alpha))); for ( ; pos < size; ++pos) colorTable[pos] = last_color; @@ -1511,7 +1510,10 @@ QSGTexture *QQuickShapeGradientCache::get(const QQuickShapeGradientCacheKey &gra if (!tx) { static const int W = 1024; // texture size is 1024x1 QImage gradTab(W, 1, QImage::Format_RGBA8888_Premultiplied); - generateGradientColorTable(grad, reinterpret_cast<uint *>(gradTab.bits()), W, 1.0f); + if (!grad.stops.isEmpty()) + generateGradientColorTable(grad, reinterpret_cast<uint *>(gradTab.bits()), W, 1.0f); + else + gradTab.fill(Qt::black); tx = new QSGPlainTexture; tx->setImage(gradTab); switch (grad.spread) { |