Repository navigation
fix: stop UiImage handing its caller's image handle to the completer - #78
Draft
orestesgaolin wants to merge 1 commit into
Draft
orestesgaolin wants to merge 1 commit into
orestesgaolin wants to merge 1 commit into
Conversation
An ImageStreamCompleter owns and disposes the ImageInfo it is given, but UiImage._loadAsync wrapped the caller's own ui.Image. BlurHashState decodes one image, keeps the handle in _image and builds a new UiImage from it on every build, so the first image cache eviction disposes that handle and the next resolve throws "Bad state: Cannot clone a disposed image" (fluttercommunity#40, fluttercommunity#46, fluttercommunity#74). UiImage now hands over a clone, and BlurHashState owns its handle: it releases the previous image when a newer decode lands, drops a decode that arrives after the widget is gone, and disposes the current one on unmount. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Author
|
Human note: we're testing this fix internally now and will probably roll out to prod to confirm it fixes it in the wild |
Author
|
Human note 2: I know this PR gives AI slop vibes, but perhaps it may be useful to build proper fix |
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.
Fixes the
Bad state: Cannot clone a disposed imagereported in #40, #46 and #74.Cause
ImageInfodocuments that the completer, not the caller, owns the image:UiImage._loadAsyncputs the caller's own handle into thatImageInfo, andBlurHashStatedecodes one image, keeps the handle in_imageand builds a newUiImagefrom it on every build. The first time the image cache drops the entry — a platform memory-pressure notification callsPaintingBinding.handleMemoryPressure, which clears it — the completer disposes the state's handle. The next resolve of the same handle callsclone()on it and throws.That is why the reports say it only happens next to a network image and after a lifecycle change: both are what make the cache evict.
Change
UiImage._loadAsynchands overimage.clone()and keeps its own handle.BlurHashStateowns that handle: it releases the previous image when a newer decode lands, disposes a decode that arrives after the widget is gone, and disposes the current one indispose(). Without this the clone would turn the crash into a leaked image per mount.BlurHashState.debugDecodedImage(@visibleForTesting) so the disposal is testable.Test
test/blur_hash_dispose_test.dartkeeps aBlurHashmounted, drops the image cache, and changes aMediaQuerydependency so the provider re-resolves — a rotation, a keyboard or a safe-area inset does the same thing in an app.On
master:With this change:
The second test asserts the decoded image is released on unmount.
On #47
#47 adds an
errorBuilderto the sameImage. That stops Flutter rethrowing, but the handle is still shared and still disposed, so the placeholder just silently stops rendering. This change removes the cause instead.🤖 Generated with Claude Code