From 4f606a46348a9ada935a2c8553feff1f474e4de1 Mon Sep 17 00:00:00 2001 From: MASTERsj01 Date: Tue, 17 Mar 2026 19:19:47 +0530 Subject: [PATCH] fix: replace raw console.log() with p5._friendlyError() in WebGL modules (resolves #8651) --- src/webgl/3d_primitives.js | 14 +++++++------- src/webgl/ShapeBuilder.js | 6 +++--- src/webgl/p5.Camera.js | 4 ++-- src/webgl/p5.RendererGL.js | 16 +++++----------- src/webgl/text.js | 4 ++-- src/webgl/utils.js | 10 ++++------ 6 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/webgl/3d_primitives.js b/src/webgl/3d_primitives.js index bafd307b7e..5102ce7293 100644 --- a/src/webgl/3d_primitives.js +++ b/src/webgl/3d_primitives.js @@ -1698,7 +1698,7 @@ function primitives3D(p5, fn){ if (detail <= 50) { arcGeom._edgesToVertices(arcGeom); } else if (this.states.strokeColor) { - console.log( + p5._friendlyError( `Cannot apply a stroke to an ${shape} with more than 50 detail` ); } @@ -2243,7 +2243,7 @@ function primitives3D(p5, fn){ if (detailX <= 1 && detailY <= 1) { planeGeom._makeTriangleEdges()._edgesToVertices(); } else if (this.states.strokeColor) { - console.log( + p5._friendlyError( 'Cannot draw stroke on plane objects with more' + ' than 1 detailX or 1 detailY' ); @@ -2327,7 +2327,7 @@ function primitives3D(p5, fn){ if (detailX <= 4 && detailY <= 4) { boxGeom._edgesToVertices(); } else if (this.states.strokeColor) { - console.log( + p5._friendlyError( 'Cannot draw stroke on box objects with more' + ' than 4 detailX or 4 detailY' ); @@ -2391,7 +2391,7 @@ function primitives3D(p5, fn){ if (detailX <= 24 && detailY <= 24) { ellipsoidGeom._makeTriangleEdges()._edgesToVertices(); } else if (this.states.strokeColor) { - console.log( + p5._friendlyError( 'Cannot draw stroke on ellipsoids with more' + ' than 24 detailX or 24 detailY' ); @@ -2432,7 +2432,7 @@ function primitives3D(p5, fn){ if (detailX <= 24 && detailY <= 16) { cylinderGeom._makeTriangleEdges()._edgesToVertices(); } else if (this.states.strokeColor) { - console.log( + p5._friendlyError( 'Cannot draw stroke on cylinder objects with more' + ' than 24 detailX or 16 detailY' ); @@ -2473,7 +2473,7 @@ function primitives3D(p5, fn){ if (detailX <= 24 && detailY <= 16) { coneGeom._makeTriangleEdges()._edgesToVertices(); } else if (this.states.strokeColor) { - console.log( + p5._friendlyError( 'Cannot draw stroke on cone objects with more' + ' than 24 detailX or 16 detailY' ); @@ -2541,7 +2541,7 @@ function primitives3D(p5, fn){ if (detailX <= 24 && detailY <= 16) { torusGeom._makeTriangleEdges()._edgesToVertices(); } else if (this.states.strokeColor) { - console.log( + p5._friendlyError( 'Cannot draw strokes on torus object with more' + ' than 24 detailX or 16 detailY' ); diff --git a/src/webgl/ShapeBuilder.js b/src/webgl/ShapeBuilder.js index 124fa62bfa..54054d0e60 100644 --- a/src/webgl/ShapeBuilder.js +++ b/src/webgl/ShapeBuilder.js @@ -438,13 +438,13 @@ export class ShapeBuilder { function begincallback(type) { if (type !== libtess.primitiveType.GL_TRIANGLES) { - console.log(`expected TRIANGLES but got type: ${type}`); + 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`); } } function errorcallback(errno) { - console.log('error callback'); - console.log(`error number: ${errno}`); + 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`); + } // callback for when segments intersect and must be split diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 5dcca97a20..1fd86e8c68 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -206,14 +206,14 @@ class Camera { if (near <= 0.0001) { near = 0.01; - console.log( + p5._friendlyError( 'Avoid perspective near plane values close to or below 0. ' + 'Setting value to 0.01.' ); } if (far < near) { - console.log( + p5._friendlyError( 'Perspective far plane value is less than near plane value. ' + 'Nothing will be shown.' ); diff --git a/src/webgl/p5.RendererGL.js b/src/webgl/p5.RendererGL.js index a17bd29334..bee2081265 100644 --- a/src/webgl/p5.RendererGL.js +++ b/src/webgl/p5.RendererGL.js @@ -250,9 +250,7 @@ class RendererGL extends Renderer3D { count ); } catch (e) { - console.log( - "🌸 p5.js says: Instancing is only supported in WebGL2 mode" - ); + p5._friendlyError("Instancing is only supported in WebGL2 mode."); } } } else if (this._curShader.shaderType === 'text') { @@ -292,9 +290,7 @@ class RendererGL extends Renderer3D { count ); } catch (e) { - console.log( - "🌸 p5.js says: Instancing is only supported in WebGL2 mode" - ); + p5._friendlyError("Instancing is only supported in WebGL2 mode."); } } } else { @@ -305,9 +301,7 @@ class RendererGL extends Renderer3D { try { gl.drawArraysInstanced(glMode, 0, geometry.vertices.length, count); } catch (e) { - console.log( - "🌸 p5.js says: Instancing is only supported in WebGL2 mode" - ); + p5._friendlyError("Instancing is only supported in WebGL2 mode."); } } } @@ -351,7 +345,7 @@ class RendererGL extends Renderer3D { _setAttributes(key, value) { if (typeof this._pInst._glAttributes === "undefined") { - console.log( + p5._friendlyError( "You are trying to use setAttributes on a p5.Graphics object " + "that does not use a WEBGL renderer." ); @@ -538,7 +532,7 @@ class RendererGL extends Renderer3D { loadPixels() { //@todo_FES if (this._pInst._glAttributes.preserveDrawingBuffer !== true) { - console.log( + p5._friendlyError( "loadPixels only works in WebGL when preserveDrawingBuffer " + "is true." ); diff --git a/src/webgl/text.js b/src/webgl/text.js index 2a2f5d66d3..bb9c611191 100644 --- a/src/webgl/text.js +++ b/src/webgl/text.js @@ -674,7 +674,7 @@ function text(p5, fn) { Renderer3D.prototype._renderText = function (line, x, y, maxY, minY) { if (!this.states.textFont || typeof this.states.textFont === 'string') { - console.log( + p5._friendlyError( 'WEBGL: you must load and set a font before drawing text. See `loadFont` and `textFont` for more details.' ); return; @@ -684,7 +684,7 @@ function text(p5, fn) { } if (!p5.Font.hasGlyphData(this.states.textFont)) { - console.log( + p5._friendlyError( 'WEBGL: only Opentype (.otf) and Truetype (.ttf) fonts with glyph data are supported. Make sure to set the font using textFont() before drawing text.' ); return; diff --git a/src/webgl/utils.js b/src/webgl/utils.js index c5c6e3d7c9..0a9c9a2a56 100644 --- a/src/webgl/utils.js +++ b/src/webgl/utils.js @@ -276,9 +276,8 @@ export function setWebGLUniformValue(shader, uniform, data, getTexture, gl) { data > gl.TEXTURE31 || data !== Math.ceil(data) ) { - console.log( - "🌸 p5.js says: " + - "You're trying to use a number as the data for a texture." + + p5._friendlyError( + "You're trying to use a number as the data for a texture." + "Please use a texture.", ); return; @@ -313,9 +312,8 @@ export function setWebGLUniformValue(shader, uniform, data, getTexture, gl) { data > gl.TEXTURE31 || data !== Math.ceil(data) ) { - console.log( - "🌸 p5.js says: " + - "You're trying to use a number as the data for a texture." + + p5._friendlyError( + "You're trying to use a number as the data for a texture." + "Please use a texture.", ); break;