p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

size() throws error with p5.Graphics

Open stalgiag opened this issue 4 years ago • 7 comments

Most appropriate sub-area of p5.js?

  • [x] Core/Environment/Rendering

Details about the bug:

  • p5.js version: 1.1.9
  • Web browser and version: latest Firefox and Chrome
  • Operating System: macOS 14
  • Steps to reproduce this:

p5.Graphics.size() throws this error:

TypeError: setting getter-only property "canvas"

This is specific to p5.Graphics. Other p5.Element-derived objects can resize as expected.

Here is an example sketch.

stalgiag avatar Dec 18 '20 18:12 stalgiag

Note that p5.Graphics.resizeCanvas()is a perfectly functioning workaround for this but this should still be fixed or a friendlier error should be thrown.

stalgiag avatar Dec 18 '20 18:12 stalgiag

there is nothing in reference page about size method

highonweb avatar Dec 23 '20 12:12 highonweb

Hi! p5.Graphics extends p5.Element which has a size() method.

Here it is in the library.

stalgiag avatar Dec 23 '20 14:12 stalgiag

can I try to fix this issue ?

highonweb avatar Dec 23 '20 17:12 highonweb

Sure @highonweb !

stalgiag avatar Dec 24 '20 14:12 stalgiag

@highonweb thanks! I think the size() method won't work for p5.Graphics because it needs a bit more than simply resizing the element, and so resizeCanvas() is the correct method to use. To fix this issue, you could use a friendly error message to alert users trying to call this method to use resizeCanvas() instead.

lmccart avatar Dec 24 '20 19:12 lmccart

@stalgiag can you review my PR

highonweb avatar Dec 25 '20 13:12 highonweb