@@ -70,6 +70,10 @@ class JsiSkVertices : public JsiSkWrappingSkPtrHostObject<SkVertices> {
70
70
if (count >= 3 && !arguments[2 ].isNull () && !arguments[2 ].isUndefined ()) {
71
71
auto jsiTexs = arguments[2 ].asObject (runtime).asArray (runtime);
72
72
auto texsSize = jsiTexs.size (runtime);
73
+ if (texsSize != positionsSize) {
74
+ throw jsi::JSError (runtime, " The number of texture coordinates must "
75
+ " match the number of positions" );
76
+ }
73
77
texs.reserve (texsSize);
74
78
for (int i = 0 ; i < texsSize; i++) {
75
79
auto point = JsiSkPoint::fromValue (
@@ -81,6 +85,11 @@ class JsiSkVertices : public JsiSkWrappingSkPtrHostObject<SkVertices> {
81
85
if (count >= 4 && !arguments[3 ].isNull () && !arguments[3 ].isUndefined ()) {
82
86
auto jsiColors = arguments[3 ].asObject (runtime).asArray (runtime);
83
87
auto colorsSize = jsiColors.size (runtime);
88
+ if (colorsSize != positionsSize) {
89
+ throw jsi::JSError (
90
+ runtime,
91
+ " The number of colors must match the number of positions" );
92
+ }
84
93
colors.reserve (colorsSize);
85
94
for (int i = 0 ; i < colorsSize; i++) {
86
95
SkColor color = JsiSkColor::fromValue (
@@ -132,9 +141,11 @@ class JsiSkVertices : public JsiSkWrappingSkPtrHostObject<SkVertices> {
132
141
// builder.indices());
133
142
// }
134
143
// auto vertices = builder.detach();
135
- auto vertices = SkVertices::MakeCopy (
136
- mode, positionsSize, positions.data (), texs.data (), colors.data (),
137
- indicesSize, indices.data ());
144
+ auto vertices =
145
+ SkVertices::MakeCopy (mode, positionsSize, positions.data (),
146
+ texs.size () > 0 ? texs.data () : nullptr ,
147
+ colors.size () > 0 ? colors.data () : nullptr ,
148
+ indicesSize, indices.data ());
138
149
return jsi::Object::createFromHostObject (
139
150
runtime,
140
151
std::make_shared<JsiSkVertices>(context, std::move (vertices)));
0 commit comments