From 9e143ed735134cf29edf0b0d5f80260d67999401 Mon Sep 17 00:00:00 2001 From: Saksham Jain Date: Sun, 1 Mar 2026 19:39:55 +0530 Subject: [PATCH] fix: replace console.warn with p5._friendlyError in light.js and material.js - light.js: Replace 6 console.warn calls with p5._friendlyError() (lightFalloff negative values, spotLight argument format, concentration) - material.js: Replace 3 console.warn calls with p5._friendlyError() (textureMode invalid mode, blendMode DARKEST/LIGHTEST unsupported) - All messages now respect p5.disableFriendlyErrors setting --- src/webgl/light.js | 33 +++++++++++++++++++-------------- src/webgl/material.js | 25 ++++++++++++++----------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/webgl/light.js b/src/webgl/light.js index 7197cb70d8..ed4d36108f 100644 --- a/src/webgl/light.js +++ b/src/webgl/light.js @@ -1233,22 +1233,25 @@ p5.prototype.lightFalloff = function ( if (constantAttenuation < 0) { constantAttenuation = 0; - console.warn( - 'Value of constant argument in lightFalloff() should be never be negative. Set to 0.' + p5._friendlyError( + 'Value of constant argument in lightFalloff() should be never be negative. Set to 0.', + 'lightFalloff' ); } if (linearAttenuation < 0) { linearAttenuation = 0; - console.warn( - 'Value of linear argument in lightFalloff() should be never be negative. Set to 0.' + p5._friendlyError( + 'Value of linear argument in lightFalloff() should be never be negative. Set to 0.', + 'lightFalloff' ); } if (quadraticAttenuation < 0) { quadraticAttenuation = 0; - console.warn( - 'Value of quadratic argument in lightFalloff() should be never be negative. Set to 0.' + p5._friendlyError( + 'Value of quadratic argument in lightFalloff() should be never be negative. Set to 0.', + 'lightFalloff' ); } @@ -1257,8 +1260,9 @@ p5.prototype.lightFalloff = function ( (linearAttenuation === 0 && quadraticAttenuation === 0) ) { constantAttenuation = 1; - console.warn( - 'Either one of the three arguments in lightFalloff() should be greater than zero. Set constant argument to 1.' + p5._friendlyError( + 'Either one of the three arguments in lightFalloff() should be greater than zero. Set constant argument to 1.', + 'lightFalloff' ); } @@ -1636,10 +1640,10 @@ p5.prototype.spotLight = function ( break; default: - console.warn( - `Sorry, input for spotlight() is not in prescribed format. Too ${ - length < 3 ? 'few' : 'many' - } arguments were provided` + p5._friendlyError( + `Sorry, input for spotlight() is not in prescribed format. Too ${length < 3 ? 'few' : 'many' + } arguments were provided.`, + 'spotLight' ); return this; } @@ -1668,8 +1672,9 @@ p5.prototype.spotLight = function ( if (concentration !== undefined && concentration < 1) { concentration = 1; - console.warn( - 'Value of concentration needs to be greater than 1. Setting it to 1' + p5._friendlyError( + 'Value of concentration needs to be greater than 1. Setting it to 1.', + 'spotLight' ); } else if (concentration === undefined) { concentration = 100; diff --git a/src/webgl/material.js b/src/webgl/material.js index d3fbb8d0a6..d97be194b6 100644 --- a/src/webgl/material.js +++ b/src/webgl/material.js @@ -1189,7 +1189,7 @@ p5.prototype.shader = function (s) { * * */ -p5.prototype.baseMaterialShader = function() { +p5.prototype.baseMaterialShader = function () { this._assert3d('baseMaterialShader'); return this._renderer.baseMaterialShader(); }; @@ -1284,7 +1284,7 @@ p5.prototype.baseMaterialShader = function() { * * */ -p5.prototype.baseNormalShader = function() { +p5.prototype.baseNormalShader = function () { this._assert3d('baseNormalShader'); return this._renderer.baseNormalShader(); }; @@ -1347,7 +1347,7 @@ p5.prototype.baseNormalShader = function() { * * */ -p5.prototype.baseColorShader = function() { +p5.prototype.baseColorShader = function () { this._assert3d('baseColorShader'); return this._renderer.baseColorShader(); }; @@ -1620,7 +1620,7 @@ p5.prototype.baseColorShader = function() { * * */ -p5.prototype.baseStrokeShader = function() { +p5.prototype.baseStrokeShader = function () { this._assert3d('baseStrokeShader'); return this._renderer.baseStrokeShader(); }; @@ -2071,8 +2071,9 @@ p5.prototype.texture = function (tex) { */ p5.prototype.textureMode = function (mode) { if (mode !== constants.IMAGE && mode !== constants.NORMAL) { - console.warn( - `You tried to set ${mode} textureMode only supports IMAGE & NORMAL ` + p5._friendlyError( + `You tried to set ${mode} textureMode only supports IMAGE & NORMAL.`, + 'textureMode' ); } else { this._renderer.textureMode = mode; @@ -3191,7 +3192,7 @@ p5.prototype.metalness = function (metallic) { * transparency internally, e.g. via vertex colors * @return {Number[]} Normalized numbers array */ -p5.RendererGL.prototype._applyColorBlend = function(colors, hasTransparency) { +p5.RendererGL.prototype._applyColorBlend = function (colors, hasTransparency) { const gl = this.GL; const isTexture = this.drawMode === constants.TEXTURE; @@ -3278,8 +3279,9 @@ p5.RendererGL.prototype._applyBlendMode = function () { ); gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE); } else { - console.warn( - 'blendMode(DARKEST) does not work in your browser in WEBGL mode.' + p5._friendlyError( + 'blendMode(DARKEST) does not work in your browser in WEBGL mode.', + 'blendMode' ); } break; @@ -3291,8 +3293,9 @@ p5.RendererGL.prototype._applyBlendMode = function () { ); gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE); } else { - console.warn( - 'blendMode(LIGHTEST) does not work in your browser in WEBGL mode.' + p5._friendlyError( + 'blendMode(LIGHTEST) does not work in your browser in WEBGL mode.', + 'blendMode' ); } break;