You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[p5.js 2.0+ Bug Report]: createCanvas overrides the value set by pixelDensity #9221
following this example on the pixelDensity documentation page, calling createCanvas after pixelDensity sets the pixel density back to default, meanwhile the documentation claims otherwise: https://p5js.org/reference/p5/pixelDensity/
Snippet:
functionsetup(){// Set the pixel density to 3.pixelDensity(3);console.log("pd:"+pixelDensity())// logs 3createCanvas(100,100);background(200);circle(50,50,70);consoel.log(pixelDensity())// logs the device default, 1 in my case}
I've peeked into p5js code, createCanvas reinitializes the renderer and pixel desnisty is reset to device default
changed the title [-][p5.js 2.0+ Bug Report]: createCanvas ovverides the value set by pixelDensity[/-][+][p5.js 2.0+ Bug Report]: createCanvas overrides the value set by pixelDensity[/+]on Sep 27, 2026
Activity
[-][p5.js 2.0+ Bug Report]: createCanvas ovverides the value set by pixelDensity[/-][+][p5.js 2.0+ Bug Report]: createCanvas overrides the value set by pixelDensity[/+]devnishantt commentedon Sep 28, 2026
I ran into this as described: pixelDensity() before createCanvas() is reset
when the renderer is recreated.
I treated it as a code bug (the docs already show that order) and opened a
fix with P2D + WEBGL tests: #9226
Happy to change the approach if you'd rather store density on the p5 instance.