Skip to content

Commit 4f606a4

Browse files
committed
fix: replace raw console.log() with p5._friendlyError() in WebGL modules (resolves #8651)
1 parent 666c425 commit 4f606a4

6 files changed

Lines changed: 23 additions & 31 deletions

File tree

src/webgl/3d_primitives.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ function primitives3D(p5, fn){
16981698
if (detail <= 50) {
16991699
arcGeom._edgesToVertices(arcGeom);
17001700
} else if (this.states.strokeColor) {
1701-
console.log(
1701+
p5._friendlyError(
17021702
`Cannot apply a stroke to an ${shape} with more than 50 detail`
17031703
);
17041704
}
@@ -2243,7 +2243,7 @@ function primitives3D(p5, fn){
22432243
if (detailX <= 1 && detailY <= 1) {
22442244
planeGeom._makeTriangleEdges()._edgesToVertices();
22452245
} else if (this.states.strokeColor) {
2246-
console.log(
2246+
p5._friendlyError(
22472247
'Cannot draw stroke on plane objects with more' +
22482248
' than 1 detailX or 1 detailY'
22492249
);
@@ -2327,7 +2327,7 @@ function primitives3D(p5, fn){
23272327
if (detailX <= 4 && detailY <= 4) {
23282328
boxGeom._edgesToVertices();
23292329
} else if (this.states.strokeColor) {
2330-
console.log(
2330+
p5._friendlyError(
23312331
'Cannot draw stroke on box objects with more' +
23322332
' than 4 detailX or 4 detailY'
23332333
);
@@ -2391,7 +2391,7 @@ function primitives3D(p5, fn){
23912391
if (detailX <= 24 && detailY <= 24) {
23922392
ellipsoidGeom._makeTriangleEdges()._edgesToVertices();
23932393
} else if (this.states.strokeColor) {
2394-
console.log(
2394+
p5._friendlyError(
23952395
'Cannot draw stroke on ellipsoids with more' +
23962396
' than 24 detailX or 24 detailY'
23972397
);
@@ -2432,7 +2432,7 @@ function primitives3D(p5, fn){
24322432
if (detailX <= 24 && detailY <= 16) {
24332433
cylinderGeom._makeTriangleEdges()._edgesToVertices();
24342434
} else if (this.states.strokeColor) {
2435-
console.log(
2435+
p5._friendlyError(
24362436
'Cannot draw stroke on cylinder objects with more' +
24372437
' than 24 detailX or 16 detailY'
24382438
);
@@ -2473,7 +2473,7 @@ function primitives3D(p5, fn){
24732473
if (detailX <= 24 && detailY <= 16) {
24742474
coneGeom._makeTriangleEdges()._edgesToVertices();
24752475
} else if (this.states.strokeColor) {
2476-
console.log(
2476+
p5._friendlyError(
24772477
'Cannot draw stroke on cone objects with more' +
24782478
' than 24 detailX or 16 detailY'
24792479
);
@@ -2541,7 +2541,7 @@ function primitives3D(p5, fn){
25412541
if (detailX <= 24 && detailY <= 16) {
25422542
torusGeom._makeTriangleEdges()._edgesToVertices();
25432543
} else if (this.states.strokeColor) {
2544-
console.log(
2544+
p5._friendlyError(
25452545
'Cannot draw strokes on torus object with more' +
25462546
' than 24 detailX or 16 detailY'
25472547
);

src/webgl/ShapeBuilder.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,13 @@ export class ShapeBuilder {
438438

439439
function begincallback(type) {
440440
if (type !== libtess.primitiveType.GL_TRIANGLES) {
441-
console.log(`expected TRIANGLES but got type: ${type}`);
441+
p5._friendlyError(`Unexpected tessellation type: expected TRIANGLES but got type: ${type}. If you see this, please report it as a bug at https://github.com/processing/p5.js/issues`);
442442
}
443443
}
444444

445445
function errorcallback(errno) {
446-
console.log('error callback');
447-
console.log(`error number: ${errno}`);
446+
p5._friendlyError(`Tessellation error (error number: ${errno}). If you see this, please report it as a bug at https://github.com/processing/p5.js/issues`);
447+
448448
}
449449

450450
// callback for when segments intersect and must be split

src/webgl/p5.Camera.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ class Camera {
206206

207207
if (near <= 0.0001) {
208208
near = 0.01;
209-
console.log(
209+
p5._friendlyError(
210210
'Avoid perspective near plane values close to or below 0. ' +
211211
'Setting value to 0.01.'
212212
);
213213
}
214214

215215
if (far < near) {
216-
console.log(
216+
p5._friendlyError(
217217
'Perspective far plane value is less than near plane value. ' +
218218
'Nothing will be shown.'
219219
);

src/webgl/p5.RendererGL.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,7 @@ class RendererGL extends Renderer3D {
250250
count
251251
);
252252
} catch (e) {
253-
console.log(
254-
"🌸 p5.js says: Instancing is only supported in WebGL2 mode"
255-
);
253+
p5._friendlyError("Instancing is only supported in WebGL2 mode.");
256254
}
257255
}
258256
} else if (this._curShader.shaderType === 'text') {
@@ -292,9 +290,7 @@ class RendererGL extends Renderer3D {
292290
count
293291
);
294292
} catch (e) {
295-
console.log(
296-
"🌸 p5.js says: Instancing is only supported in WebGL2 mode"
297-
);
293+
p5._friendlyError("Instancing is only supported in WebGL2 mode.");
298294
}
299295
}
300296
} else {
@@ -305,9 +301,7 @@ class RendererGL extends Renderer3D {
305301
try {
306302
gl.drawArraysInstanced(glMode, 0, geometry.vertices.length, count);
307303
} catch (e) {
308-
console.log(
309-
"🌸 p5.js says: Instancing is only supported in WebGL2 mode"
310-
);
304+
p5._friendlyError("Instancing is only supported in WebGL2 mode.");
311305
}
312306
}
313307
}
@@ -351,7 +345,7 @@ class RendererGL extends Renderer3D {
351345

352346
_setAttributes(key, value) {
353347
if (typeof this._pInst._glAttributes === "undefined") {
354-
console.log(
348+
p5._friendlyError(
355349
"You are trying to use setAttributes on a p5.Graphics object " +
356350
"that does not use a WEBGL renderer."
357351
);
@@ -538,7 +532,7 @@ class RendererGL extends Renderer3D {
538532
loadPixels() {
539533
//@todo_FES
540534
if (this._pInst._glAttributes.preserveDrawingBuffer !== true) {
541-
console.log(
535+
p5._friendlyError(
542536
"loadPixels only works in WebGL when preserveDrawingBuffer " +
543537
"is true."
544538
);

src/webgl/text.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ function text(p5, fn) {
674674

675675
Renderer3D.prototype._renderText = function (line, x, y, maxY, minY) {
676676
if (!this.states.textFont || typeof this.states.textFont === 'string') {
677-
console.log(
677+
p5._friendlyError(
678678
'WEBGL: you must load and set a font before drawing text. See `loadFont` and `textFont` for more details.'
679679
);
680680
return;
@@ -684,7 +684,7 @@ function text(p5, fn) {
684684
}
685685

686686
if (!p5.Font.hasGlyphData(this.states.textFont)) {
687-
console.log(
687+
p5._friendlyError(
688688
'WEBGL: only Opentype (.otf) and Truetype (.ttf) fonts with glyph data are supported. Make sure to set the font using textFont() before drawing text.'
689689
);
690690
return;

src/webgl/utils.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,8 @@ export function setWebGLUniformValue(shader, uniform, data, getTexture, gl) {
276276
data > gl.TEXTURE31 ||
277277
data !== Math.ceil(data)
278278
) {
279-
console.log(
280-
"🌸 p5.js says: " +
281-
"You're trying to use a number as the data for a texture." +
279+
p5._friendlyError(
280+
"You're trying to use a number as the data for a texture." +
282281
"Please use a texture.",
283282
);
284283
return;
@@ -313,9 +312,8 @@ export function setWebGLUniformValue(shader, uniform, data, getTexture, gl) {
313312
data > gl.TEXTURE31 ||
314313
data !== Math.ceil(data)
315314
) {
316-
console.log(
317-
"🌸 p5.js says: " +
318-
"You're trying to use a number as the data for a texture." +
315+
p5._friendlyError(
316+
"You're trying to use a number as the data for a texture." +
319317
"Please use a texture.",
320318
);
321319
break;

0 commit comments

Comments
 (0)