From 273036f273f6b6429e71127355bd2d9df4cb55bc Mon Sep 17 00:00:00 2001 From: Dan Field Date: Tue, 1 Mar 2022 10:13:39 -0800 Subject: [PATCH 1/3] Fix invalid usage of typed data detected via dart_debug=true --- lib/ui/painting/fragment_program.cc | 3 ++- lib/ui/painting/fragment_program.h | 2 +- lib/ui/painting/path.cc | 11 +++++++---- lib/ui/painting/vertices.cc | 13 +++++++++---- lib/ui/painting/vertices.h | 8 ++++---- tools/gn | 2 +- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/ui/painting/fragment_program.cc b/lib/ui/painting/fragment_program.cc index 12a1824d0b8f7..9156302789ea8 100644 --- a/lib/ui/painting/fragment_program.cc +++ b/lib/ui/painting/fragment_program.cc @@ -55,7 +55,7 @@ void FragmentProgram::init(std::string sksl, bool debugPrintSksl) { fml::RefPtr FragmentProgram::shader( Dart_Handle shader, - const tonic::Float32List& uniforms, + tonic::Float32List& uniforms, Dart_Handle samplers) { auto sampler_shaders = tonic::DartConverter>::FromDart(samplers); @@ -69,6 +69,7 @@ fml::RefPtr FragmentProgram::shader( for (size_t i = 0; i < uniform_count; i++) { uniform_floats[i] = uniforms[i]; } + uniforms.Release(); std::vector> sk_samplers(sampler_shaders.size()); for (size_t i = 0; i < sampler_shaders.size(); i++) { ImageShader* image_shader = sampler_shaders[i]; diff --git a/lib/ui/painting/fragment_program.h b/lib/ui/painting/fragment_program.h index 06cf429b32e42..a1b518a3b8168 100644 --- a/lib/ui/painting/fragment_program.h +++ b/lib/ui/painting/fragment_program.h @@ -31,7 +31,7 @@ class FragmentProgram : public RefCountedDartWrappable { void init(std::string sksl, bool debugPrintSksl); fml::RefPtr shader(Dart_Handle shader, - const tonic::Float32List& uniforms, + tonic::Float32List& uniforms, Dart_Handle samplers); static void RegisterNatives(tonic::DartLibraryNatives* natives); diff --git a/lib/ui/painting/path.cc b/lib/ui/painting/path.cc index 223f3058b5506..be9762dd7e44a 100644 --- a/lib/ui/painting/path.cc +++ b/lib/ui/painting/path.cc @@ -253,16 +253,17 @@ void CanvasPath::addPathWithMatrix(CanvasPath* path, double dy, tonic::Float64List& matrix4) { if (!path) { + matrix4.Release(); Dart_ThrowException( ToDart("Path.addPathWithMatrix called with non-genuine Path.")); return; } SkMatrix matrix = ToSkMatrix(matrix4); + matrix4.Release(); matrix.setTranslateX(matrix.getTranslateX() + dx); matrix.setTranslateY(matrix.getTranslateY() + dy); mutable_path().addPath(path->path(), matrix, SkPath::kAppend_AddPathMode); - matrix4.Release(); resetVolatility(); } @@ -281,16 +282,17 @@ void CanvasPath::extendWithPathAndMatrix(CanvasPath* path, double dy, tonic::Float64List& matrix4) { if (!path) { + matrix4.Release(); Dart_ThrowException( ToDart("Path.addPathWithMatrix called with non-genuine Path.")); return; } SkMatrix matrix = ToSkMatrix(matrix4); + matrix4.Release(); matrix.setTranslateX(matrix.getTranslateX() + dx); matrix.setTranslateY(matrix.getTranslateY() + dy); mutable_path().addPath(path->path(), matrix, SkPath::kExtend_AddPathMode); - matrix4.Release(); resetVolatility(); } @@ -317,10 +319,11 @@ void CanvasPath::shift(Dart_Handle path_handle, double dx, double dy) { void CanvasPath::transform(Dart_Handle path_handle, tonic::Float64List& matrix4) { + auto sk_matrix = ToSkMatrix(matrix4); + matrix4.Release(); fml::RefPtr path = CanvasPath::Create(path_handle); auto& other_mutable_path = path->mutable_path(); - mutable_path().transform(ToSkMatrix(matrix4), &other_mutable_path); - matrix4.Release(); + mutable_path().transform(sk_matrix, &other_mutable_path); } tonic::Float32List CanvasPath::getBounds() { diff --git a/lib/ui/painting/vertices.cc b/lib/ui/painting/vertices.cc index 8617aee51f554..bfa79e396465a 100644 --- a/lib/ui/painting/vertices.cc +++ b/lib/ui/painting/vertices.cc @@ -45,10 +45,10 @@ void Vertices::RegisterNatives(tonic::DartLibraryNatives* natives) { bool Vertices::init(Dart_Handle vertices_handle, SkVertices::VertexMode vertex_mode, - const tonic::Float32List& positions, - const tonic::Float32List& texture_coordinates, - const tonic::Int32List& colors, - const tonic::Uint16List& indices) { + tonic::Float32List& positions, + tonic::Float32List& texture_coordinates, + tonic::Int32List& colors, + tonic::Uint16List& indices) { UIDartState::ThrowIfUIOperationsProhibited(); uint32_t builderFlags = 0; if (texture_coordinates.data()) { @@ -70,22 +70,27 @@ bool Vertices::init(Dart_Handle vertices_handle, if (positions.data()) { DecodePoints(positions, builder.positions()); } + positions.Release(); if (texture_coordinates.data()) { // SkVertices::Builder assumes equal numbers of elements FML_DCHECK(positions.num_elements() == texture_coordinates.num_elements()); DecodePoints(texture_coordinates, builder.texCoords()); } + texture_coordinates.Release(); + if (colors.data()) { // SkVertices::Builder assumes equal numbers of elements FML_DCHECK(positions.num_elements() / 2 == colors.num_elements()); DecodeInts(colors, builder.colors()); } + colors.Release(); if (indices.data()) { std::copy(indices.data(), indices.data() + indices.num_elements(), builder.indices()); } + indices.Release(); auto vertices = fml::MakeRefCounted(); vertices->vertices_ = builder.detach(); diff --git a/lib/ui/painting/vertices.h b/lib/ui/painting/vertices.h index 1b4c8601df806..0a6555be9ae84 100644 --- a/lib/ui/painting/vertices.h +++ b/lib/ui/painting/vertices.h @@ -26,10 +26,10 @@ class Vertices : public RefCountedDartWrappable { static bool init(Dart_Handle vertices_handle, SkVertices::VertexMode vertex_mode, - const tonic::Float32List& positions, - const tonic::Float32List& texture_coordinates, - const tonic::Int32List& colors, - const tonic::Uint16List& indices); + tonic::Float32List& positions, + tonic::Float32List& texture_coordinates, + tonic::Int32List& colors, + tonic::Uint16List& indices); const sk_sp& vertices() const { return vertices_; } diff --git a/tools/gn b/tools/gn index abf28364d9712..addc0cccea615 100755 --- a/tools/gn +++ b/tools/gn @@ -206,7 +206,7 @@ def to_gn_args(args): gn_args['dart_lib_export_symbols'] = False if runtime_mode == 'debug': - gn_args['dart_runtime_mode'] = 'develop' + gn_args['dart_debug'] = args.unoptimized elif runtime_mode == 'jit_release': gn_args['dart_runtime_mode'] = 'release'; else: From 6061594c08032cb0e644af4f75c027fd936f9841 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Tue, 1 Mar 2022 13:36:32 -0800 Subject: [PATCH 2/3] Fix order --- lib/ui/painting/vertices.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ui/painting/vertices.cc b/lib/ui/painting/vertices.cc index bfa79e396465a..9b73939a70b2d 100644 --- a/lib/ui/painting/vertices.cc +++ b/lib/ui/painting/vertices.cc @@ -70,26 +70,27 @@ bool Vertices::init(Dart_Handle vertices_handle, if (positions.data()) { DecodePoints(positions, builder.positions()); } - positions.Release(); if (texture_coordinates.data()) { // SkVertices::Builder assumes equal numbers of elements FML_DCHECK(positions.num_elements() == texture_coordinates.num_elements()); DecodePoints(texture_coordinates, builder.texCoords()); } - texture_coordinates.Release(); if (colors.data()) { // SkVertices::Builder assumes equal numbers of elements FML_DCHECK(positions.num_elements() / 2 == colors.num_elements()); DecodeInts(colors, builder.colors()); } - colors.Release(); if (indices.data()) { std::copy(indices.data(), indices.data() + indices.num_elements(), builder.indices()); } + + positions.Release(); + texture_coordinates.Release(); + colors.Release(); indices.Release(); auto vertices = fml::MakeRefCounted(); From a9029102c8eefc7f248980bb26f818598a7fd5ea Mon Sep 17 00:00:00 2001 From: Dan Field Date: Tue, 1 Mar 2022 21:18:53 -0800 Subject: [PATCH 3/3] Revert changes to gn --- tools/gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/gn b/tools/gn index addc0cccea615..abf28364d9712 100755 --- a/tools/gn +++ b/tools/gn @@ -206,7 +206,7 @@ def to_gn_args(args): gn_args['dart_lib_export_symbols'] = False if runtime_mode == 'debug': - gn_args['dart_debug'] = args.unoptimized + gn_args['dart_runtime_mode'] = 'develop' elif runtime_mode == 'jit_release': gn_args['dart_runtime_mode'] = 'release'; else: