Skip to content

Commit 41a0e50

Browse files
committed
use dependency injection pattern for friendly errors check
1 parent d12a012 commit 41a0e50

2 files changed

Lines changed: 23 additions & 17 deletions

File tree

src/core/p5.Renderer3D.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,10 @@ const webGPUAddonMessage = 'Add the WebGPU add-on to your project and pass WEBGP
19971997
function renderer3D(p5, fn) {
19981998
p5.Renderer3D = Renderer3D;
19991999

2000+
ShapeBuilder.prototype.friendlyErrorsDisabled = function() {
2001+
return Boolean(p5.disableFriendlyErrors);
2002+
};
2003+
20002004
/**
20012005
* Creates a <a href="#/p5/p5.StorageBuffer">`p5.StorageBuffer`</a>, which is
20022006
* a block of data that shaders can read from, and compute shaders

src/webgl/ShapeBuilder.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export class ShapeBuilder {
4545
this.bufferStrides = { ...INITIAL_BUFFER_STRIDES };
4646
}
4747

48+
friendlyErrorsDisabled() {
49+
return false;
50+
}
51+
4852
constructFromContours(shape, contours) {
4953
if (this._useUserVertexProperties){
5054
this._resetUserVertexProperties();
@@ -151,24 +155,22 @@ export class ShapeBuilder {
151155
const vertexCount = this.geometry.vertices.length;
152156
const MAX_SAFE_TESSELLATION_VERTICES = 50000;
153157

154-
if (vertexCount > MAX_SAFE_TESSELLATION_VERTICES) {
155-
const p5Class = this.renderer._pInst.constructor;
156-
if (
157-
!p5Class.disableFriendlyErrors &&
158-
!this.renderer._largeTessellationAcknowledged
159-
) {
160-
const proceed = window.confirm(
161-
'🌸 p5.js says:\n\n' +
162-
`This shape has ${vertexCount} vertices. Tessellating shapes with this ` +
163-
'many vertices can be very slow and may cause your browser to become ' +
164-
'unresponsive.\n\n' +
165-
'Do you want to continue tessellating this shape?'
166-
);
167-
if (!proceed) {
168-
return;
169-
}
170-
this.renderer._largeTessellationAcknowledged = true;
158+
if (
159+
vertexCount > MAX_SAFE_TESSELLATION_VERTICES &&
160+
!this.friendlyErrorsDisabled() &&
161+
!this.renderer._largeTessellationAcknowledged
162+
) {
163+
const proceed = window.confirm(
164+
'🌸 p5.js says:\n\n' +
165+
`This shape has ${vertexCount} vertices. Tessellating shapes with this ` +
166+
'many vertices can be very slow and may cause your browser to become ' +
167+
'unresponsive.\n\n' +
168+
'Do you want to continue tessellating this shape?'
169+
);
170+
if (!proceed) {
171+
return;
171172
}
173+
this.renderer._largeTessellationAcknowledged = true;
172174
}
173175

174176
this.isProcessingVertices = true;

0 commit comments

Comments
 (0)