P5.js: Ellipse not checking for undefined arguments.

Created on 6 Apr 2020  路  3Comments  路  Source: processing/p5.js

Most appropriate sub-area of p5.js?

  • [ ] Color
  • [x] Core/Environment/Rendering
  • [ ] Data
  • [ ] Dom
  • [ ] Events
  • [ ] Image
  • [ ] IO
  • [ ] Math
  • [ ] Typography
  • [ ] Utilities
  • [ ] WebGL
  • [ ] Other (specify if possible)

Details about the bug:

  • p5.js version: v0.10.2
  • Web browser and version: 80.0.3987.163
  • Operating System: Win 10 x64 18362
  • Steps to reproduce this:
class Particle {
    constructor(x, y, rad) {
        this.pos = createVector(x, y);
        this.rad = rad;
    }
    display() {
        ellipse(this.pos.x, this.pos.y, this.radius, this.radius);
    }
}

let particles = [];
function setup() {

  createCanvas(700, 700);
  for (let i = 0; i < 100; i++) {
    let x = floor(random() * width);
    let y = floor(random() * height);
    particles[i] = new Particle(x, y, 50);
  }
}

function draw() {
  background(255);

  stroke(0);
  fill(0);
  for (let i = 0; i < 100; i++) {
    particles[i].display();
  }
}

This doesn't create an ellipse on the screen because this.radius is undefined. But it doesn't throw any error either, which led to an hour of debugging just to find that an undefined variable was being passed into ellipse.

bug

All 3 comments

Welcome! 馃憢 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.

Hi, many functions in p5 do not throw an error for wrong arguments by itself. An error is usually only thrown if the wrong argument results in some error in the execution of the function.

But the un-minified library has the Friendly Error System enabled, which logs a message for wrong arguments. I know this won't completely solve your issue, and sometimes the logged message can be inaccurate ( another known issue which needs to be looked into ), I think it can provide some help here by telling you that something is wrong.

I would say that an undefined width/height in an eclipse should result in some error inside the function.
But for now I'll default to using the non minified version. Thanks.

Was this page helpful?
0 / 5 - 0 ratings