Fix npe during skia dispatch of drawAtlas (flutter/engine#55497)
Colors are optionally provided, so make sure to null check the array. Fixes https://github.com/flutter/flutter/issues/155783
This commit is contained in:
@@ -254,12 +254,15 @@ void DlSkCanvasDispatcher::drawAtlas(const sk_sp<DlImage> atlas,
|
||||
return;
|
||||
}
|
||||
std::vector<SkColor> sk_colors;
|
||||
sk_colors.reserve(count);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
sk_colors.push_back(colors[i].argb());
|
||||
if (colors != nullptr) {
|
||||
sk_colors.reserve(count);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
sk_colors.push_back(colors[i].argb());
|
||||
}
|
||||
}
|
||||
canvas_->drawAtlas(skia_atlas.get(), xform, ToSkRects(tex), sk_colors.data(),
|
||||
count, ToSk(mode), ToSk(sampling), ToSkRect(cullRect),
|
||||
canvas_->drawAtlas(skia_atlas.get(), xform, ToSkRects(tex),
|
||||
sk_colors.empty() ? nullptr : sk_colors.data(), count,
|
||||
ToSk(mode), ToSk(sampling), ToSkRect(cullRect),
|
||||
safe_paint(render_with_attributes));
|
||||
}
|
||||
void DlSkCanvasDispatcher::drawDisplayList(
|
||||
|
||||
@@ -1364,6 +1364,36 @@ void main() async {
|
||||
final int rgba = data.buffer.asUint32List()[0];
|
||||
expect(rgba, 0xFF0000FF);
|
||||
});
|
||||
|
||||
test('DrawAtlas with no colors does not crash',
|
||||
() async {
|
||||
final Image testImage = await createTestImage();
|
||||
final PictureRecorder recorder = PictureRecorder();
|
||||
final Canvas canvas = Canvas(recorder);
|
||||
// Make a drawAtlas call that should be solid red.
|
||||
canvas.drawAtlas(
|
||||
testImage,
|
||||
[
|
||||
RSTransform.fromComponents(
|
||||
rotation: 0,
|
||||
scale: 10,
|
||||
anchorX: 0,
|
||||
anchorY: 0,
|
||||
translateX: 0,
|
||||
translateY: 0,
|
||||
),
|
||||
],
|
||||
[const Rect.fromLTWH(0, 0, 1, 1)],
|
||||
[],
|
||||
BlendMode.dst,
|
||||
null,
|
||||
Paint(),
|
||||
);
|
||||
|
||||
final Image resultImage = await recorder.endRecording().toImage(1, 1);
|
||||
final ByteData? data = await resultImage.toByteData();
|
||||
expect(data, isNotNull);
|
||||
});
|
||||
}
|
||||
|
||||
Future<Image> createTestImage() async {
|
||||
|
||||
Reference in New Issue
Block a user