Dasher: Fixed crash when dash array contains ZERO length segments or ZERO gap segments

This commit is contained in:
subhransu mohanty
2019-07-30 09:44:35 +09:00
committed by Subhransu
parent a1e46310f6
commit fc548c1bbf
3 changed files with 16 additions and 4 deletions

View File

@@ -33,6 +33,15 @@ VDasher::VDasher(const float *dashArray, size_t size)
mIndex = 0;
mCurrentLength = 0;
mDiscard = false;
//if the dash array contains ZERO length
// segments or ZERO lengths gaps we could
// optimize those usecase.
for (size_t i = 0; i < mArraySize; i++) {
if (!vCompare(mDashArray->length, 0.0f))
mNoLength = false;
if (!vCompare(mDashArray->gap, 0.0f))
mNoGap = false;
}
}
void VDasher::moveTo(const VPointF &p)
@@ -178,7 +187,8 @@ void VDasher::cubicTo(const VPointF &cp1, const VPointF &cp2, const VPointF &e)
VPath VDasher::dashed(const VPath &path)
{
if (path.empty()) return VPath();
if (path.empty() || mNoLength) return VPath();
if (mNoGap) return path;
mResult = {};
mResult.reserve(path.points().size(), path.elements().size());

View File

@@ -46,10 +46,12 @@ private:
VPointF mCurPt;
size_t mIndex{0}; /* index to the dash Array */
float mCurrentLength;
bool mDiscard;
float mDashOffset{0};
VPath mResult;
bool mStartNewSegment=true;
bool mDiscard{false};
bool mStartNewSegment{true};
bool mNoLength{true};
bool mNoGap{true};
};
V_END_NAMESPACE

View File

@@ -26,7 +26,7 @@ void VDrawable::preprocess(const VRect &clip)
if (mStroke.enable) {
if (mStroke.mDash.size()) {
VDasher dasher(mStroke.mDash.data(), mStroke.mDash.size());
mPath = dasher.dashed(mPath);
mPath.clone(dasher.dashed(mPath));
}
mRasterizer.rasterize(std::move(mPath), mStroke.cap, mStroke.join,
mStroke.width, mStroke.meterLimit, clip);