diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 27d44d477b7..789fe2251bd 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -438,7 +438,13 @@ void SkDevice::drawGlyphRunList(SkCanvas* canvas, void SkDevice::simplifyGlyphRunRSXFormAndRedraw(SkCanvas* canvas, const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) { - for (const sktext::GlyphRun& run : glyphRunList) { + // glyphRunList typically spans into the canvas's scratch GlyphRunBuilder + // storage. drawGlyphRunList() below can reenter SkCanvas::drawTextBlob() + // (e.g. via a glyph SkDrawable that draws a text blob), which reuses and + // reallocates that storage and would invalidate our iterator. Take a + // local copy of the runs before drawing any of them. + std::vector localRuns(glyphRunList.begin(), glyphRunList.end()); + for (const sktext::GlyphRun& run : localRuns) { if (run.scaledRotations().empty()) { auto subList = glyphRunList.builder()->makeGlyphRunList(run, paint, {0, 0}); this->drawGlyphRunList(canvas, subList, paint);