未验证 提交 50de4692 编写于 作者: L liyuqian 提交者: GitHub

Check the matrix in pushTransform (#8758)

Fixes flutter/flutter#31650
上级 7df8b7af
......@@ -15,8 +15,8 @@ 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.
// We need this even if transform_ is initialized to identity 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
......
......@@ -57,10 +57,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
///
/// See [pop] for details about the operation stack.
EngineLayer pushTransform(Float64List matrix4) {
if (matrix4 == null)
throw new ArgumentError('"matrix4" argument cannot be null');
if (matrix4.length != 16)
throw new ArgumentError('"matrix4" must have 16 entries.');
assert(_matrix4IsValid(matrix4));
return _pushTransform(matrix4);
}
EngineLayer _pushTransform(Float64List matrix4) native 'SceneBuilder_pushTransform';
......
......@@ -42,6 +42,7 @@ bool _offsetIsValid(Offset offset) {
bool _matrix4IsValid(Float64List matrix4) {
assert(matrix4 != null, 'Matrix4 argument was null.');
assert(matrix4.length == 16, 'Matrix4 must have 16 entries.');
assert(matrix4.every((double value) => value.isFinite), 'Matrix4 entries must be finite.');
return true;
}
......
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:typed_data' show Float64List;
import 'dart:ui';
import 'package:test/test.dart';
void main() {
test('pushTransform validates the matrix', () {
final SceneBuilder builder = SceneBuilder();
final Float64List matrix4 = Float64List.fromList(<double>[
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1,
]);
expect(builder.pushTransform(matrix4), isNotNull);
final Float64List matrix4WrongLength = Float64List.fromList(<double>[
1, 0, 0, 0,
0, 1, 0,
0, 0, 1, 0,
0, 0, 0,
]);
expect(
() => builder.pushTransform(matrix4WrongLength),
throwsA(const TypeMatcher<AssertionError>()),
);
final Float64List matrix4NaN = Float64List.fromList(<double>[
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, double.nan,
]);
expect(
() => builder.pushTransform(matrix4NaN),
throwsA(const TypeMatcher<AssertionError>()),
);
final Float64List matrix4Infinity = Float64List.fromList(<double>[
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, double.infinity,
]);
expect(
() => builder.pushTransform(matrix4NaN),
throwsA(const TypeMatcher<AssertionError>()),
);
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册