Update our lastmoveindex if addPath ended with a kClose verb
Bug: 1153516
Change-Id: Id6ab162ba3bbf902048009ae2b48b2c67f814b99
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/342616
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 020f89c..d530bd2 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -1368,6 +1368,10 @@
if (int numWeights = src->fPathRef->countWeights()) {
memcpy(newWeights, src->fPathRef->conicWeights(), numWeights * sizeof(newWeights[0]));
}
+ // fiddle with fLastMoveToIndex, as we do in SkPath::close()
+ if ((SkPathVerb)fPathRef->verbsEnd()[-1] == SkPathVerb::kClose) {
+ fLastMoveToIndex ^= ~fLastMoveToIndex >> (8 * sizeof(fLastMoveToIndex) - 1);
+ }
return this->dirtyAfterEdit();
}
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index e647d44..cb068ac 100644
--- a/tests/PathTest.cpp
+++ b/tests/PathTest.cpp
@@ -5803,3 +5803,12 @@
test_addRect_and_trailing_lineTo(r);
test_addPath_and_injected_moveTo(r);
}
+
+DEF_TEST(path_addpath_crbug_1153516, r) {
+ // When we add a path to another path, we need to sniff out in case the argument ended
+ // with a kClose, in which case we need to fiddle with our lastMoveIndex (as ::close() does)
+ SkPath p1, p2;
+ p1.addRect({143,226,200,241});
+ p1.addPath(p1);
+ p1.lineTo(262,513); // this should not assert
+}