diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2022-11-10 14:35:01 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-11-11 19:12:19 +0000 |
commit | 173624e486e7fd6a00567a3802b05561c0d7e389 (patch) | |
tree | 4cf82efb8bd2c053569383110d5a53befdc9c0e6 | |
parent | c47795814be231e1d51c04e115d0518663c1cc83 (diff) | |
download | qtdeclarative-173624e486e7fd6a00567a3802b05561c0d7e389.tar.gz |
Handle missing stops gracefully in Shape gradients
Fixes: QTBUG-108298
Change-Id: Ib6e004a1518aec4c786c3aeebcd74e6cb11f45ef
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
(cherry picked from commit e52efc3defe102a55b45b013764ba1bae1fe5a1b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-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 f19c4e637b..53d1378d89 100644 --- a/src/quickshapes/qquickshape.cpp +++ b/src/quickshapes/qquickshape.cpp @@ -1440,6 +1440,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); @@ -1477,8 +1478,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; @@ -1513,7 +1512,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) { |