diff --git a/src/core/friendly_errors/param_validator.js b/src/core/friendly_errors/param_validator.js index 6277304168..07c5889f60 100644 --- a/src/core/friendly_errors/param_validator.js +++ b/src/core/friendly_errors/param_validator.js @@ -551,7 +551,7 @@ function validateParams(p5, fn, lifecycles) { args.every(arg => arg === undefined) ) { const undefinedErrorMessage = `🌸 p5.js says: All arguments for ${func}() are undefined. There is likely an error in the code.`; - + console.log(undefinedErrorMessage); return { success: false, error: undefinedErrorMessage diff --git a/src/math/noise.js b/src/math/noise.js index fcc26a42d8..9c81c7ae47 100644 --- a/src/math/noise.js +++ b/src/math/noise.js @@ -265,6 +265,7 @@ function noise(p5, fn){ * @return {Number} Perlin noise value at specified coordinates. */ fn.noise = function(x, y = 0, z = 0) { + if (x === null || y === null || z === null) return NaN; if (perlin == null) { perlin = new Array(PERLIN_SIZE + 1); for (let i = 0; i < PERLIN_SIZE + 1; i++) { diff --git a/test/unit/math/noise.js b/test/unit/math/noise.js index 3b95dd403f..ca567f752e 100644 --- a/test/unit/math/noise.js +++ b/test/unit/math/noise.js @@ -34,6 +34,16 @@ suite('Noise', function() { }); }); + // Test for null arguments + suite('null arguments', function() { + test('null should returns NaN', function() { + assert.isNaN(mockP5Prototype.noise(null)); + }); + test('noise(0, 0, null) returns NaN', function() { + assert.isNaN(mockP5Prototype.noise(0, 0, null)); + }); + }); + // Test for noiseSeed suite('p5.prototype.noiseSeed', function() { beforeEach(function() {