fix: createGraphics inherits pixelDensity from parent sketch.#8558
Merged
davepagurek merged 1 commit intoprocessing:dev-2.0from Feb 23, 2026
Merged
Conversation
…s ver.2x, createGraphics() used window.devicePixelRatio for the graphics buffer's pixel density, ignoring the parent sketch setting. This caused graphics buffer to render pixelDensity(2) on retina displays even when pixelDensity(1) was explicitly set. The fix makes graphics buffer renderers (isMainCanvas === false) inherit pixelDensity from the parent sketch via pInst._pInst._renderer instead of always using window.devicePixelRatio.
davepagurek
approved these changes
Feb 23, 2026
Contributor
davepagurek
left a comment
There was a problem hiding this comment.
Great work @imrinahru! Nice work on the tests too!
Contributor
|
@all-contributors please add @imrinahru for bug, code, test |
Contributor
|
I've put up a pull request to add @imrinahru! 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In p5.js ver.2x, createGraphics() used window.devicePixelRatio for the graphics buffer's pixel density, ignoring the parent sketch setting. This caused graphics buffer to render pixelDensity(2) on retina displays even when pixelDensity(1) was explicitly set.
The fix makes graphics buffer renderers (isMainCanvas === false) inherit pixelDensity from the parent sketch via pInst._pInst._renderer instead of always using window.devicePixelRatio.
Resolves #8289
Changes:
createGraphics()now inherits the parent sketch'spixelDensityinstead of always usingwindow.devicePixelRatio.Bug: When calling
pixelDensity(1)on the main sketch,createGraphics()still created a buffer with the screen's native pixel density (e.g., 2 on Retina/HiDPI displays).Cause: In the v2.0 refactoring,
_pixelDensitywas moved from the sketch to theRendererconstructor. For graphics buffers (isMainCanvas === false), the renderer always set:This ignores the parent sketch's
pixelDensitysetting entirely.Fix: For graphics buffer renderers, inherit the pixel density from the parent sketch via
pInst._pInst._renderer._pixelDensity, falling back towindow.devicePixelRatioif unavailable.Files changed:
src/core/p5.Renderer.js— Fixed the constructor to inherit pixelDensity for non-main-canvas rendererstest/unit/core/rendering.js— Added 3 unit tests for pixelDensity inheritanceScreenshots of the change:
Bug happened with code:
After fix:

Additional notes:
There were 4 pre-existing failures in
p5.Shader.jsandtypography.js, which looked unrelated from my fix.PR Checklist
npm run lintpasses