processing / p5.js

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —
http://p5js.org/
GNU Lesser General Public License v2.1
21.51k stars 3.29k forks source link

canvas doesn't load, no error thrown when invalid parameter passed to `textWrap()` #6997

Closed rbstrachan closed 4 months ago

rbstrachan commented 5 months ago

Most appropriate sub-area of p5.js?

p5.js version

1.9.2

Web browser and version

Firefox 125.0.2

Operating system

Linux Ubuntu 22.04 LTS

Steps to reproduce this

Steps

  1. Create a new project.
  2. Pass an invalid parameter, such as a number or string, to textWrap() in setup().

Snippet

function setup() {
  createCanvas(400, 400);
  textWrap(50);
}

Notes

When I first tried to use textWrap(), I wrongly assumed it took the maximum width, in pixels, of the text before wrapping occurred, so I did something like textWrap(width * 2 / 3);. The canvas disappeared and no error was given. I believe I've seen this behavior before with other methods but I can't remember which ones.

welcome[bot] commented 5 months ago

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you!

rbstrachan commented 5 months ago

It seems that the textWrap() function (src/typography/attributes.js#L541) does do a simple if then check to throw an error, but doesn't use p5._validateParameters().

limzykenneth commented 4 months ago

@rbstrachan Issue is as you identified and using p5._validateParameters() does solve the issue as intended. However, there are some unit test related issue that was left uncaught for awhile and I need to fix that before fixing this. Will try to do so today. Thanks.