Skip to content

[2.0] image() mislogs error when using canvas as first parameter #7579

Closed
@juaogeneroso

Description

@juaogeneroso

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
}

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    Completed

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions