Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[p5.js 2.0 Beta Bug Report]: image() mislogs error when using canvas as first parameter #7579

Open
2 of 17 tasks
juaogeneroso opened this issue Feb 26, 2025 · 3 comments
Open
2 of 17 tasks

Comments

@juaogeneroso
Copy link

juaogeneroso commented Feb 26, 2025

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

p5.js v2.0.0-beta.2 February 3, 2025

Web browser and version

Chrome 133.0.6943.141 (Official Build) (64-bit) (cohort: M133 Rollout), Firefox 135.0.1 20250216192613

Operating system

Windows 10

Steps to reproduce this

Steps:

  1. Create a canvas with createCanvas() and, optionally, an offscreen canvas with createGraphics().
  2. Call image() with a canvas as the main parameter.
  3. The canvas is drawn correctly as an image, but it still logs a friendly error: "p5.js says: Expected Image or Element or Texture or Framebuffer or FramebufferTexture at the first parameter in image()."

Doing the above with image() attached to an offscreen canvas doesn't log errors.

Snippet:

let defaultCanvas, graphicsCanvas;

async function setup() {
  defaultCanvas = createCanvas(400, 400);
  graphicsCanvas = createGraphics(400, 400);
  
  graphicsCanvas.background(0); // doesn't affect results, but shows that the image() function still works
  
  image(defaultCanvas, 0, 0); // consoles error
  image(graphicsCanvas, 0, 0); // consoles error
  graphicsCanvas.image(defaultCanvas, 0, 0); // doesn't console error
  graphicsCanvas.image(graphicsCanvas, 0, 0); // doesn't console error
}
Copy link

welcome bot commented Feb 26, 2025

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!

@swastikCommits
Copy link

Can I work on this?

@swastikCommits
Copy link

swastikCommits commented Mar 1, 2025

const testParamType = (param, type) => {
..... rest of the code ...

if (!matches && type.name === 'Image' && 
    param && (param.canvas || (param.elt && param.elt.tagName === 'CANVAS'))) {
  matches = true;
}

return matches ? 0 : 1;

};

This might fix the issue because of the friendly error in src/core/friendly_errors/validate_params.js

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

No branches or pull requests

2 participants