Repository navigation
fix(web): keep a cached canvas image's inline data alive - #751
Merged
Merged
Conversation
8 of 17 tasks
ImageSource.Key names inline data by its address, and the web canvas image cache did not keep the source, so a collected buffer's address could come back in a new buffer of the same length and be handed the old image, which the cache never evicts. The entry now keeps its source, as the Apple canvas cache does since nsgo-dev#737 and the Linux and Windows canvas image slots already did. Part of nsgo-dev#738
houko
force-pushed
the
fix/web-canvas-image-key
branch
from
November 19, 2026 00:25
bf983a3 to
30c169d
Compare
Collaborator
Author
|
Reviewed independently. The web |
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.
Summary
Part of #738: the web canvas cache. The Apple canvas cache was fixed in #737; the other caches #738 lists are left to it.
ImageSource.Keynames inline data by its backing address and length, and the web canvas image cache (canvasImage) did not keep the source. Once an app dropped an inlineDatabuffer, the garbage collector could hand its address to a new buffer of the same length, and a canvas or shader drawing the new bytes got the old image. Since the web cache never evicts an entry, that wrong image stayed for the life of the surface. The entry now keeps its source, as the Apple canvas cache does since #737 and the Linux and Windows canvas image slots already did, so the address cannot be reused while its key is cached.The cache already keeps each decoded
Imageelement for the life of the surface, so this also keeps the encoded bytes it was made from; it does not change how many entries are kept.Targets
core,base,ui,tsx, thensgotool)Screenshots
None. No visual change for an app whose buffers stay alive.
Verification
GOOS=js GOARCH=wasm go vet ./internal/platform/webgo tool nsgo test -target web ./internal/platform/web(headless Chromium): 19 passed, 1 skipped, including the newTestCanvasImageKeepsItsInlineData, which checks that the cached entry holds the source's bytes and that the same bytes reuse the entry.Checklist
CHANGELOG.md'sUnreleasedhas a line covering this and fix(apple): keep a cached canvas image's inline data alive #737.