Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Prevent unnecessary WebGL canvas recreation in noSmooth() in dev-2.0 #7574

Open
wants to merge 1 commit into
base: dev-2.0
Choose a base branch
from

Conversation

HarshitaKatariya
Copy link

Resolve #7548
Issue

Calling noSmooth() inside draw() in WebGL mode recreates the canvas because setAttributes('antialias', false) is called every time. This causes unexpected behavior, including loss of canvas positioning and state.

Fix:
Before setting antialias to false, we check if it's already false.
If it's already disabled, we skip calling setAttributes(), preventing unnecessary canvas recreation.

Why This Fix?
Optimizes performance: Avoids reinitializing the WebGL canvas every frame.
Prevents unintended side effects: Keeps canvas position and other properties intact.
Aligns with expected behavior: In 2D mode, noSmooth() doesn’t recreate the canvas, so WebGL should behave similarly.

Before
Output with noSmooth()
Not display any output..

Output without noSmooth()
After

After
After fix issue.
Output with noSmooth() as well as without noSmooth().
After

Alternative Solution Considered
Updating the documentation to explicitly state that calling noSmooth() after initialization will recreate the canvas. This can still be done in addition to this fix.

Testing
✅ Verified in both 2D and WebGL renderers.
✅ noSmooth() works correctly in setup() and draw().
✅ No canvas recreation occurs unless truly necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant