Skip to content

Commit e5d43dd

Browse files
authored
Fix invalid usage of typed data detected via dart_debug=true (flutter#31745)
1 parent 4d63750 commit e5d43dd

5 files changed

Lines changed: 24 additions & 14 deletions

File tree

lib/ui/painting/fragment_program.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void FragmentProgram::init(std::string sksl, bool debugPrintSksl) {
5555

5656
fml::RefPtr<FragmentShader> FragmentProgram::shader(
5757
Dart_Handle shader,
58-
const tonic::Float32List& uniforms,
58+
tonic::Float32List& uniforms,
5959
Dart_Handle samplers) {
6060
auto sampler_shaders =
6161
tonic::DartConverter<std::vector<ImageShader*>>::FromDart(samplers);
@@ -69,6 +69,7 @@ fml::RefPtr<FragmentShader> FragmentProgram::shader(
6969
for (size_t i = 0; i < uniform_count; i++) {
7070
uniform_floats[i] = uniforms[i];
7171
}
72+
uniforms.Release();
7273
std::vector<sk_sp<SkShader>> sk_samplers(sampler_shaders.size());
7374
for (size_t i = 0; i < sampler_shaders.size(); i++) {
7475
ImageShader* image_shader = sampler_shaders[i];

lib/ui/painting/fragment_program.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class FragmentProgram : public RefCountedDartWrappable<FragmentProgram> {
3131
void init(std::string sksl, bool debugPrintSksl);
3232

3333
fml::RefPtr<FragmentShader> shader(Dart_Handle shader,
34-
const tonic::Float32List& uniforms,
34+
tonic::Float32List& uniforms,
3535
Dart_Handle samplers);
3636

3737
static void RegisterNatives(tonic::DartLibraryNatives* natives);

lib/ui/painting/path.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,17 @@ void CanvasPath::addPathWithMatrix(CanvasPath* path,
253253
double dy,
254254
tonic::Float64List& matrix4) {
255255
if (!path) {
256+
matrix4.Release();
256257
Dart_ThrowException(
257258
ToDart("Path.addPathWithMatrix called with non-genuine Path."));
258259
return;
259260
}
260261

261262
SkMatrix matrix = ToSkMatrix(matrix4);
263+
matrix4.Release();
262264
matrix.setTranslateX(matrix.getTranslateX() + dx);
263265
matrix.setTranslateY(matrix.getTranslateY() + dy);
264266
mutable_path().addPath(path->path(), matrix, SkPath::kAppend_AddPathMode);
265-
matrix4.Release();
266267
resetVolatility();
267268
}
268269

@@ -281,16 +282,17 @@ void CanvasPath::extendWithPathAndMatrix(CanvasPath* path,
281282
double dy,
282283
tonic::Float64List& matrix4) {
283284
if (!path) {
285+
matrix4.Release();
284286
Dart_ThrowException(
285287
ToDart("Path.addPathWithMatrix called with non-genuine Path."));
286288
return;
287289
}
288290

289291
SkMatrix matrix = ToSkMatrix(matrix4);
292+
matrix4.Release();
290293
matrix.setTranslateX(matrix.getTranslateX() + dx);
291294
matrix.setTranslateY(matrix.getTranslateY() + dy);
292295
mutable_path().addPath(path->path(), matrix, SkPath::kExtend_AddPathMode);
293-
matrix4.Release();
294296
resetVolatility();
295297
}
296298

@@ -317,10 +319,11 @@ void CanvasPath::shift(Dart_Handle path_handle, double dx, double dy) {
317319

318320
void CanvasPath::transform(Dart_Handle path_handle,
319321
tonic::Float64List& matrix4) {
322+
auto sk_matrix = ToSkMatrix(matrix4);
323+
matrix4.Release();
320324
fml::RefPtr<CanvasPath> path = CanvasPath::Create(path_handle);
321325
auto& other_mutable_path = path->mutable_path();
322-
mutable_path().transform(ToSkMatrix(matrix4), &other_mutable_path);
323-
matrix4.Release();
326+
mutable_path().transform(sk_matrix, &other_mutable_path);
324327
}
325328

326329
tonic::Float32List CanvasPath::getBounds() {

lib/ui/painting/vertices.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ void Vertices::RegisterNatives(tonic::DartLibraryNatives* natives) {
4545

4646
bool Vertices::init(Dart_Handle vertices_handle,
4747
SkVertices::VertexMode vertex_mode,
48-
const tonic::Float32List& positions,
49-
const tonic::Float32List& texture_coordinates,
50-
const tonic::Int32List& colors,
51-
const tonic::Uint16List& indices) {
48+
tonic::Float32List& positions,
49+
tonic::Float32List& texture_coordinates,
50+
tonic::Int32List& colors,
51+
tonic::Uint16List& indices) {
5252
UIDartState::ThrowIfUIOperationsProhibited();
5353
uint32_t builderFlags = 0;
5454
if (texture_coordinates.data()) {
@@ -76,6 +76,7 @@ bool Vertices::init(Dart_Handle vertices_handle,
7676
FML_DCHECK(positions.num_elements() == texture_coordinates.num_elements());
7777
DecodePoints(texture_coordinates, builder.texCoords());
7878
}
79+
7980
if (colors.data()) {
8081
// SkVertices::Builder assumes equal numbers of elements
8182
FML_DCHECK(positions.num_elements() / 2 == colors.num_elements());
@@ -87,6 +88,11 @@ bool Vertices::init(Dart_Handle vertices_handle,
8788
builder.indices());
8889
}
8990

91+
positions.Release();
92+
texture_coordinates.Release();
93+
colors.Release();
94+
indices.Release();
95+
9096
auto vertices = fml::MakeRefCounted<Vertices>();
9197
vertices->vertices_ = builder.detach();
9298
vertices->AssociateWithDartWrapper(vertices_handle);

lib/ui/painting/vertices.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ class Vertices : public RefCountedDartWrappable<Vertices> {
2626

2727
static bool init(Dart_Handle vertices_handle,
2828
SkVertices::VertexMode vertex_mode,
29-
const tonic::Float32List& positions,
30-
const tonic::Float32List& texture_coordinates,
31-
const tonic::Int32List& colors,
32-
const tonic::Uint16List& indices);
29+
tonic::Float32List& positions,
30+
tonic::Float32List& texture_coordinates,
31+
tonic::Int32List& colors,
32+
tonic::Uint16List& indices);
3333

3434
const sk_sp<SkVertices>& vertices() const { return vertices_; }
3535

0 commit comments

Comments
 (0)