mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-02-01 16:50:33 +00:00
Dasher: Fixed crash when dash array contains ZERO length segments or ZERO gap segments
This commit is contained in:
committed by
Subhransu
parent
a1e46310f6
commit
fc548c1bbf
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user