-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
Image
disposes its image too early, causing errors such as "Cannot clone a disposed image"
#110129
Labels
a: images
Loading, displaying, rendering images
c: crash
Stack traces logged to the console
found in release: 3.0
Found to occur in 3.0
found in release: 3.1
Found to occur in 3.1
framework
flutter/packages/flutter repository. See also f: labels.
has reproducible steps
The issue has been confirmed reproducible and is ready to work on
r: fixed
Issue is closed as already fixed in a newer version
Comments
8 tasks
Image
has logical flow which disposes its image too early, causing errors such as "Cannot clone a disposed image"Image
disposes its image too early, causing errors such as "Cannot clone a disposed image"
Reproducible on logs
flutter doctor -v
|
@danagbemava-nc Thanks for the reply. Indeed I have PR it: #110131 |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
a: images
Loading, displaying, rendering images
c: crash
Stack traces logged to the console
found in release: 3.0
Found to occur in 3.0
found in release: 3.1
Found to occur in 3.1
framework
flutter/packages/flutter repository. See also f: labels.
has reproducible steps
The issue has been confirmed reproducible and is ready to work on
r: fixed
Issue is closed as already fixed in a newer version
Bug analysis and solution
Summary: Looking at
Image
. When its new image is decoded, it will immediately dispose its old image handle. However, this is logically wrong - the old image handle may still be used in the (near) future.At the first glance, this looks impossible, because when the old image handle is disposed, we will no longer give it to child widget tree. And we all know that, Flutter builds widget tree from ancestors to descendants. Therefore, as long as the ancestor (Image) provides the new image handle to its children (RawImage), its children should not use the old image handle after it is disposed.
However, it is not true and this bug is indeed there. There are some special but very widely used widgets that "breaks" this mental modal, such as the
LayoutBuilder
. When we have something likeWidgetOne(child: LayoutBuilder(builder: WidgetTwo()))
, andWidgetOne
andWidgetTwo
bothmarkNeedsBuild
(such as bysetState
), then the build order is indeed:WidgetOne - WidgetTwo(with old data) - LayoutBuilder - WidgetTwo(with new data)
. The "WidgetTwo(with old data)" will cause bugs in our case. In our case, the "old data" is equivalent to "the image handle that we have disposed", so we are indeed using a disposed image handle.Reproducible samples are given below to verify the theoretical analysis.
Steps to Reproduce
Run the following self-contained test. (I added a lot of logs so you can see what is happening)
Expected results:
No error
Actual results:
Errors. Please have a look at logs below.
Code sample
Logs
A shorter reproducible sample, if you are interested:
The text was updated successfully, but these errors were encountered: