Add canvas 2d clearing system#324
Merged
waynemwashuma merged 2 commits intoMay 27, 2026
Merged
Conversation
2 tasks
waynemwashuma
added a commit
that referenced
this pull request
May 27, 2026
## Objective - Part of #324 ## Solution N/A ## Showcase N/A ## Migration guide No migration required. ## Checklist * [ ] I have updated the documentation accordingly. * [ ] I have added tests to cover my changes.
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.
Objective
Introduce deterministic frame clearing for the Canvas2D renderer and avoid redundant window resize operations. Previously, Canvas2D rendering accumulated previous frame contents because the canvas was never cleared automatically before rendering. Additionally, resize commands always mutated the canvas even when dimensions were unchanged. This adds a dedicated canvas clearing system and optimizes resize handling.
Solution
Root cause
The Canvas2D renderer intentionally skipped clearing the canvas each frame. This caused rendered frames to persist between updates, producing visual artifacts such as:
Separately, window resize commands always triggered canvas dimension writes even when dimensions were identical, causing unnecessary canvas resets and potential rendering invalidation. This is what previously cleared the frames
Solution
Added dedicated
clearCanvas2dsystem (scheduled at the beginning of update schedule) which:2drendering contextFrame clearing is now treated as a first-class rendering stage rather than implicit renderer behavior.
Optimized resize handling
Added an early bailout for resize commands preventing unnecessary:
when dimensions have not changed.
Why this approach
Alternative approaches considered:
Those approaches couple frame lifecycle management to renderer implementations and make multi-pass rendering harder to reason about.
Using a dedicated clearing system:
The resize optimization similarly avoids unnecessary canvas mutations with minimal complexity.
Showcase
N/A
Migration guide
No migration required.
Behavioral change
Canvas2D rendering now clears the frame automatically every update cycle. Projects that intentionally relied on persistent frame accumulation for effects such as manual trails, paint-style rendering and temporal accumulation must now implement custom persistence behavior explicitly.
Checklist