From 6a28ed4830e2beb5f76f3721381bcda2d8a47397 Mon Sep 17 00:00:00 2001 From: liyuqian Date: Tue, 16 Apr 2019 20:36:25 -0700 Subject: [PATCH] Check that TransformLayer has a finite matrix (flutter/engine#8585) To catch issues like https://github.com/flutter/flutter/issues/30586 https://github.com/flutter/flutter/pull/31097 will trigger this CHECK if https://github.com/flutter/engine/pull/8467 were reverted and the transform_ were not initialized in this PR. --- .../src/flutter/flow/layers/transform_layer.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/flow/layers/transform_layer.cc b/engine/src/flutter/flow/layers/transform_layer.cc index b3b259db9e..7a41312fe6 100644 --- a/engine/src/flutter/flow/layers/transform_layer.cc +++ b/engine/src/flutter/flow/layers/transform_layer.cc @@ -6,11 +6,27 @@ namespace flow { -TransformLayer::TransformLayer() = default; +TransformLayer::TransformLayer() { + transform_.setIdentity(); +} TransformLayer::~TransformLayer() = default; void TransformLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { + // Checks (in some degree) that SkMatrix transform_ is valid and initialized. + // + // We need this even if is_set_ is true since one can call set_transform with + // an uninitialized SkMatrix. + // + // If transform_ is uninitialized, this assert may look flaky as it doesn't + // fail all the time, and some rerun may make it pass. But don't ignore it and + // just rerun the test if this is triggered, since even a flaky failure here + // may signify a potentially big problem in the code. + // + // We have to write this flaky test because there is no reliable way to test + // whether a variable is initialized or not in C++. + FML_CHECK(transform_.isFinite()); + SkMatrix child_matrix; child_matrix.setConcat(matrix, transform_);