Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5aa2913
avoid unnecessary operations during indices check
timmaffett May 5, 2023
57781a2
fix indices check in raw() to correctly check <positions.length/2
timmaffett May 5, 2023
e80a3dc
formatting
timmaffett May 5, 2023
118a38a
add tests for ckVertices doing proper parameter checks
timmaffett May 5, 2023
d692f0f
add positions.length is even check to CkVertices.raw()
timmaffett May 5, 2023
046a729
made throws in vertices_test.dart throw ArgumentError to make linux a…
timmaffett May 5, 2023
930d9ea
fix tests expected error text
timmaffett May 5, 2023
fe4db2b
changed %2!=0 check to use isOdd
timmaffett May 16, 2023
7c42cc2
Merge branch 'main' into vertices.raw
timmaffett Jun 1, 2023
a1f133a
Merge branch 'flutter:main' into vertices.raw
timmaffett Jun 1, 2023
e15299a
change vertices_test.dart to only check CkVertices for argument check…
timmaffett Jun 2, 2023
702ff22
change web_ui vertices checks to asserts and add to skwasm_impl
timmaffett Jun 2, 2023
cfcf849
fix catch for ArgumentError
timmaffett Jun 2, 2023
217de1d
added vertices checks to html render_vertices.dart, formatting
timmaffett Jun 2, 2023
8e3dcec
tweaks to tests to properly identify exception text
timmaffett Jun 2, 2023
0b2f940
fix trailing space
timmaffett Jun 2, 2023
1ad8364
match assertionerror extra slashes
timmaffett Jun 2, 2023
010c78a
correct assertion match
timmaffett Jun 2, 2023
1bc170a
fix vertices.raw test
timmaffett Jun 2, 2023
edf7ba0
added debug code to print stacktrace so see what is generating unexpe…
timmaffett Jun 2, 2023
cfe76fb
move vertices checks in painting to asserts,fix indices asserts
timmaffett Jun 2, 2023
468c585
moving vertices checsk in paint to asserts
timmaffett Jun 2, 2023
2d9dbd3
remove trailing space
timmaffett Jun 2, 2023
eeca5e1
made assert expects dependent on asserts being enabled
timmaffett Jun 2, 2023
9532396
remove non assert checks from vertices code, tests check if asserts a…
timmaffett Jun 2, 2023
4640ed2
Merge branch 'main' into vertices.raw
timmaffett Jun 5, 2023
8b06199
change to using every instead of any
timmaffett Jun 7, 2023
d0c7a97
Merge branch 'vertices.raw' of https://github.com/timmaffett/engine i…
timmaffett Jun 7, 2023
e2cf427
Merge branch 'flutter:main' into vertices.raw
timmaffett Jun 7, 2023
d303c63
fix spacing
timmaffett Jun 7, 2023
3428566
Merge branch 'vertices.raw' of https://github.com/timmaffett/engine i…
timmaffett Jun 7, 2023
f82de2b
change any use to every in vertices checks
timmaffett Jun 7, 2023
3f1f1cb
remove negation on every
timmaffett Jun 7, 2023
371b2e6
fix spacing around ==
timmaffett Jun 8, 2023
e42938d
add space after if where missing
timmaffett Jun 8, 2023
f987b94
update AUTHORS
timmaffett Jun 8, 2023
a9e8e0f
add use and disposing of invalid Vertices objects when asserts not en…
timmaffett Nov 30, 2023
0db8427
dispose of invalid vertices objects (that would be created if asserts…
timmaffett Nov 30, 2023
d8a42d6
Merge branch 'main' into vertices.raw
timmaffett Nov 30, 2023
8197599
remove trailing space
timmaffett Dec 1, 2023
4050715
Update AUTHORS
kevmoo Feb 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/ui/painting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4714,8 +4714,10 @@ class Vertices extends NativeFieldWrapperClass1 {
throw ArgumentError('"positions" and "textureCoordinates" lengths must match.');
}
if (indices != null) {
final int halfPositions = positions.length >> 1; // len/2 - we already checked that positions.length is even
for (int index = 0; index < indices.length; index += 1) {
if (indices[index] * 2 >= positions.length) {
// we need to check that `indices[index] * 2 >= positions.length`, so do it without multiplying
if (indices[index] >= halfPositions) {
throw ArgumentError(
'"indices" values must be valid indices in the positions list '
'(i.e. numbers in the range 0..${positions.length ~/ 2 - 1}), '
Expand Down
8 changes: 7 additions & 1 deletion lib/web_ui/lib/src/engine/canvaskit/vertices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class CkVertices implements ui.Vertices {
Int32List? colors,
Uint16List? indices,
}) {
if (positions.length % 2 != 0) {
Comment thread
timmaffett marked this conversation as resolved.
Outdated
throw ArgumentError('"positions" must have an even number of entries (each coordinate is an x,y pair).');
}
if (textureCoordinates != null &&
textureCoordinates.length != positions.length) {
throw ArgumentError(
Expand All @@ -55,8 +58,11 @@ class CkVertices implements ui.Vertices {
if (colors != null && colors.length * 2 != positions.length) {
throw ArgumentError('"positions" and "colors" lengths must match.');
}
// see ui.Vertices.raw() - all indices must be <(positions.length/2) because they refer to
// pairs in the positions array.
final int halfPositions = positions.length >> 1;
if (indices != null &&
indices.any((int i) => i < 0 || i >= positions.length)) {
indices.any((int i) => i < 0 || i >= halfPositions)) {
throw ArgumentError(
'"indices" values must be valid indices in the positions list.');
}
Expand Down
54 changes: 54 additions & 0 deletions lib/web_ui/test/canvaskit/vertices_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,60 @@ void testMain() {
.draw(builder.build().layerTree);
await matchGoldenFile('canvaskit_vertices_antialiased.png', region: region);
}, skip: isSafari);

test('Vertices checks', () {
try {
ui.Vertices(
ui.VertexMode.triangles,
const <ui.Offset>[ui.Offset.zero, ui.Offset.zero, ui.Offset.zero],
indices: Uint16List.fromList(const <int>[0, 2, 5]),
);
throw ArgumentError('Vertices did not throw the expected error.');
} on ArgumentError catch (e) {
expect('$e', 'Invalid argument(s): "indices" values must be valid indices in the positions list.');
}
ui.Vertices( // This one does not throw.
ui.VertexMode.triangles,
const <ui.Offset>[ui.Offset.zero],
).dispose();
ui.Vertices( // This one should not throw.
ui.VertexMode.triangles,
const <ui.Offset>[ui.Offset.zero, ui.Offset.zero, ui.Offset.zero],
indices: Uint16List.fromList(const <int>[0, 2, 1, 2, 0, 1, 2, 0]), // Uint16List implements List<int> so this is ok.
).dispose();
});

test('Vertices.raw checks', () {
try {
ui.Vertices.raw(
ui.VertexMode.triangles,
Float32List.fromList(const <double>[0.0]),
);
throw ArgumentError('Vertices.raw did not throw the expected error.');
} on ArgumentError catch (e) {
expect('$e', 'Invalid argument(s): "positions" must have an even number of entries (each coordinate is an x,y pair).');
}
try {
ui.Vertices.raw(
ui.VertexMode.triangles,
Float32List.fromList(const <double>[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]),
indices: Uint16List.fromList(const <int>[0, 2, 5]),
);
throw ArgumentError('Vertices.raw did not throw the expected error.');
} on ArgumentError catch (e) {
expect('$e', 'Invalid argument(s): "indices" values must be valid indices in the positions list.');
}
ui.Vertices.raw( // This one does not throw.
ui.VertexMode.triangles,
Float32List.fromList(const <double>[0.0, 0.0]),
).dispose();
ui.Vertices.raw( // This one should not throw.
ui.VertexMode.triangles,
Float32List.fromList(const <double>[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]),
indices: Uint16List.fromList(const <int>[0, 2, 1, 2, 0, 1, 2, 0]),
).dispose();
});

}

CkVertices _testVertices() {
Expand Down