processing / processing/p5.js

setAttributes() invalidates references to earlier canvases

Open
#5,902 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:WebGL Bug Help Wanted
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

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
  • Internalization
  • Friendly Errors
  • Other (specify if possible)
p5.js version

1.5.0

Web browser and version

107.0.1

Operating System

macOS 12.5.1

Steps to reproduce this

Calling setAttributes in WebGL mode might end up recreating the underlying canvas and renderer object.

Say you're trying to position the element, e.g. like this:

let canvas = createCanvas(100, 100, sketch.WEBGL);
// ...
canvas.position(0,0);

Unfortunately, this stops working after a setAttributes call, because after that call, canvas !== _renderer. Currently, to fix it, one would have to do:

createCanvas(100, 100, sketch.WEBGL);
setAttributes({ alpha: true });
let canvas = _renderer;
// ...
canvas.position(0,0);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing setAttributes in WebGL mode from createCanvas and the renderer recreation described in the report. Verify how the original canvas reference becomes disconnected, then confirm that positioning the canvas after setAttributes still works without reacquiring _renderer.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.