Open
Description
Most appropriate sub-area of p5.js?
- AccessibilityColorCore/Environment/RenderingDataDOMEventsImageIOMathTypographyUtilitiesWebGLBuild processUnit testingInternationalizationFriendly errorsOther (specify if possible)
p5.js version
1.11.3
Web browser and version
Chrome 133.0.6943.54
Operating system
MacOS
Steps to reproduce this
Steps:
createCanvas()
, position it, addnoSmooth()
in thedraw()
- 2D renderer, no problem
- WEBGL, breaks, creates new empty canvas?
Perhaps one isn't supposed to use noSmooth()
in the draw? I don't remember hitting this issue, but maybe never tried it before... Is that how it's supposed to behave? The refs only show examples of it in the setup()
, but it doesn't state anywhere that's the only spot for it to go. In 2D renderer, it doesn't cause an issue, so is it normal in WEBGL or a bug?
Snippet:
function setup() {
let cvn = createCanvas(300, 300)
cvn = createCanvas(300, 300, WEBGL) // breaks with noSmooth() below
cvn.position(150, 50)
background(0, 0, 255)
circle(0, 0, 100)
}
function draw(){
noSmooth() // breaks sketch in WEBGL mode
}
Activity
davepagurek commentedon Feb 15, 2025
noSmooth()
involves recreating the canvas (see also these other problems: #6369 (comment))A docs update sounds like the best option here for mentioning that the canvas will be recreated.
About positioning: I don't think we try to copy the style attribute from the last canvas when we recreate it, so that would probably be necessary to not lose the position if
setAttributes
ornoSmooth
is called after positioning. SincenoSmooth
callssetAttributes
under the good, I think that would be the spot where we'd have to add a fix.HarshitaKatariya commentedon Feb 16, 2025
Yup, setAttributes has a property that recreates the canvas, so updating the documentation of noSmooth() is a good option.
Alternatively, we can update the codebase to prevent unnecessary canvas recreation by checking if antialias is already false before calling setAttributes(). This would improve performance, maintain canvas positioning, and ensure consistency between 2D and WebGL modes.
Would it be okay to proceed with a pull request for this fix?
ImRAJAS-SAMSE commentedon Feb 16, 2025
I would like to work on this issue by modifying
setAttributes()
inp5.RendererGL.js
to prevent unnecessary canvas recreation whennoSmooth()
is called indraw()
.My Plan to Fix this issue:
antialias
is alreadyfalse
before calling_initContext()
, avoiding redundant canvas resets.position
,top
, andleft
before recreation and restore them after.noSmooth()
can cause canvas recreation if used indraw()
.Let me know if any changes are needed and should I proceed with a PR!
Thank you :)
HarshitaKatariya commentedon Feb 17, 2025
@ImRAJAS-SAMSE, I think the change might not have fully resolved the issue as expected. The canvas position still seems to be off after calling noSmooth(). Could you double-check whether the position is being correctly restored after the canvas is recreated?
ImRAJAS-SAMSE commentedon Feb 17, 2025
Hi @HarshitaKatariya, thank you for reviewing the PR! 🙌
I double-checked the fix, and during testing, the canvas retained its position correctly after calling
noSmooth()
.What I Tested:
createCanvas(300, 300, WEBGL);
and positioned it at(150, 50)
.noSmooth()
indraw()
.noSmooth()
was applied.Could you share a test case where the issue still occurs? I’d be happy to debug further if needed.
commitverse commentedon Apr 8, 2025
Hey, Bug Confirmed
I was able to reproduce the issue using a simple sketch with
WEBGL
mode andnoSmooth()
. When using:ksen0 commentedon Apr 8, 2025
Hi @commitverse looks like it actually was fixed #7557 but not yet merged! Sorry this slipped through. Will check and merge shortly. Thanks for looking into it.
The dev-2.0 fix has failing tests, though: #7574 so if you have any ideas for that, it would be helpful!