Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 15 additions & 9 deletions src/webgl/GeometryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ class GeometryBuilder {
}

let startIdx = this.geometry.vertices.length;
this.geometry.vertices.push(...this.transformVertices(input.vertices));
this.geometry.vertexNormals.push(
...this.transformNormals(input.vertexNormals)
);
this.geometry.uvs.push(...input.uvs);
for (const v of this.transformVertices(input.vertices)) {
this.geometry.vertices.push(v);
}
for (const vn of this.transformNormals(input.vertexNormals)) {
this.geometry.vertexNormals.push(vn);
}
for (const val of input.uvs) {
this.geometry.uvs.push(val);
}

const inputUserVertexProps = input.userVertexProperties;
const builtUserVertexProps = this.geometry.userVertexProperties;
Expand Down Expand Up @@ -103,15 +107,17 @@ class GeometryBuilder {
);
}
if (this.renderer.states.strokeColor) {
this.geometry.edges.push(
...input.edges.map(edge => edge.map(idx => idx + startIdx))
);
for (const edge of input.edges.map(edge => edge.map(idx => idx + startIdx))) {
this.geometry.edges.push(edge);
}
}
const vertexColors = [...input.vertexColors];
while (vertexColors.length < input.vertices.length * 4) {
vertexColors.push(...this.renderer.states.curFillColor);
}
this.geometry.vertexColors.push(...vertexColors);
for (const c of vertexColors) {
this.geometry.vertexColors.push(c);
}
}

/**
Expand Down
17 changes: 17 additions & 0 deletions test/unit/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -3089,6 +3089,23 @@ suite('p5.RendererGL', function() {
myp5.model(geom);
expect(myp5.get(5, 5)).toEqual([255, 0, 0, 255]);
});
test('does not throw with a large number of vertices', function() {
myp5.createCanvas(10, 10, myp5.WEBGL);
// Enough triangles to exceed the ~65k argument limit of Function.prototype.apply,
// which would cause a stack overflow if vertices were spread into push() calls.
const numTriangles = 30000;
expect(() => {
myp5.buildGeometry(() => {
myp5.beginShape(myp5.TRIANGLES);
for (let i = 0; i < numTriangles; i++) {
myp5.vertex(0, 0, 0);
myp5.vertex(1, 0, 0);
myp5.vertex(0, 1, 0);
}
myp5.endShape();
});
}).not.toThrow();
});
});

suite('fontWidth', function() {
Expand Down
Loading