Skip to content

Fix saveCanvas() when passing the canvas from createCanvas() or createGraphics() - #9384

Open
Akshats-git wants to merge 1 commit into
processing:mainfrom
Akshats-git:fix/savecanvas-renderer-9381
Open

Akshats-git wants to merge 1 commit into
processing:mainfrom
Akshats-git:fix/savecanvas-renderer-9381

Conversation

@Akshats-git

Copy link
Copy Markdown
Contributor

Resolves #9381

Changes:

In 2.x, createCanvas() returns a p5.Renderer and createGraphics() returns a p5.Graphics. Neither is a p5.Element anymore, so saveCanvas() did not recognise them. It treated the object as the filename and threw filename.includes is not a function. Nothing was saved.

This PR adds a check for p5.Renderer and p5.Graphics at the start of saveCanvas() and uses their .canvas. save() in src/io/files.js already does the same thing.

  • src/image/image.js: handle p5.Renderer and p5.Graphics and add them to the @param type.
  • docs/parameterData.json: same type update so FES accepts these arguments.
  • test/unit/image/downloading.js: 4 new tests on a real sketch (2D canvas, canvas with a filename and extension, WEBGL canvas, p5.Graphics). The existing tests only used a mock and never passed a canvas which is why this was missed. The new tests fail without the fix.

All six examples on the saveCanvas() reference page now save a file in Chrome and Firefox, the same as in 1.11.10.

I used an AI assistant to help fix and write the tests. I have reviewed and tested every change myself.

PR Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[p5.js 2.0+ Bug Report]: The last three saveCanvas() reference examples throw an error and save nothing

1 participant