flutter_cached_network_image icon indicating copy to clipboard operation
flutter_cached_network_image copied to clipboard

`StateError: Bad state: Cannot clone a disposed image` after app changes lifecycle

Open raulmabe opened this issue 2 years ago • 13 comments

🔙 Regression

Hi, I have received 300 events in 14 days in Sentry that some users are getting an error related with images and I think this package may have to do with it (as I do not manipulate images directly, nor another package that I have... Also the issue may be related to #513.).

I am getting these two errors after app lifecycles changes.

StateError: Bad state: Cannot clone a disposed image.
The clone() method of a previously-disposed Image was called. Once an Image object has been disposed, it can no longer be used to create handles, as the underlying data may have been released.
  File "painting.dart", line 1815, in Image.clone
  File "image_stream.dart", line 50, in ImageInfo.clone
  File "image_stream.dart", line 645, in ImageStreamCompleter.setImage
  File "zone.dart", line 1434, in _rootRunUnary
String: Bad state: Cannot clone a disposed image.
The clone() method of a previously-disposed Image was called. Once an Image object has been disposed, it can no longer be used to create handles, as the underlying data may have been released.
  File "painting.dart", line 1815, in Image.clone
  File "image_stream.dart", line 50, in ImageInfo.clone
  File "image_stream.dart", line 645, in ImageStreamCompleter.setImage
  File "zone.dart", line 1434, in _rootRunUnary

Reproduction steps

I have the following breadcrumbs (may be incomplete, but will provide more info as I get):

  1. Move the app to the background
  2. Resume the app

Configuration

flutter doctor -v

flutter doctor -v
[✓] Flutter (Channel stable, 3.0.0, on macOS 11.6 20G165 darwin-x64, locale es-ES)
    • Flutter version 3.0.0 at /Users/raulmateobeneyto/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ee4e09cce0 (2 weeks ago), 2022-05-09 16:45:18 -0700
    • Engine revision d1b9a6938a
    • Dart version 2.17.0
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/raulmateobeneyto/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] VS Code (version 1.67.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.40.0

[✓] Connected device (4 available)
    • ONEPLUS A6013 (mobile) • fe0fb3b5                             • android-arm64  • Android 11 (API 30)
    • iPhone 13 Pro (mobile) • D32273CD-17B7-4F4D-AA28-AF043DEB3851 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
    • macOS (desktop)        • macos                                • darwin-x64     • macOS 11.6 20G165 darwin-x64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 101.0.4951.64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Plugin version: cached_network_image: ^3.2.1

Platform:

  • [X] :iphone: iOS
  • [ ] :robot: Android

raulmabe avatar May 24 '22 16:05 raulmabe

Same here, except I don't even need to pop a page.

The exception come from: sky_engine->ui->painting.dart From the method:

    if (_disposed) {
      throw StateError(
        'Cannot clone a disposed image.\n'
        'The clone() method of a previously-disposed Image was called. Once an '
        'Image object has been disposed, it can no longer be used to create '
        'handles, as the underlying data may have been released.'
      );
    }
    assert(!_image._disposed);
    return Image._(_image);
  }

hbock-42 avatar Jun 21 '22 12:06 hbock-42

It happens only in iOS to me, I'll update the issue.

raulmabe avatar Aug 09 '22 09:08 raulmabe

Any update on this? I can see it on both android and iOS.

himeshp avatar Sep 19 '22 15:09 himeshp

Hi I have this issue but I don't have cached_network_image as a dependency direct nor transitive so it might be possible its not from this package. But I do have a package that has report similar issue see https://github.com/fluttercommunity/flutter_blurhash/pull/47

Edit: Found this https://github.com/flutter/flutter/issues/110129. Issue is fixed but not yet in stable. Fix is in master

Mayb3Nots avatar Oct 12 '22 18:10 Mayb3Nots

Same here, I'm using bugsnag and it happens on both iOS and android. I'm also having BlurHash used for certain images preload.

alanlanglois avatar Feb 28 '23 10:02 alanlanglois

Im pretty sure this is already fixed in the latest stable version of Flutter. Could you reproduce it with flutter 3.7.4?

Mayb3Nots avatar Feb 28 '23 13:02 Mayb3Nots

I got it in production using Flutter 3.7.7

alanlanglois avatar Mar 15 '23 16:03 alanlanglois

My app uses the (currently) latest Flutter 3.10.6, and I'm also experiencing this error after I go to home and then go back to the app. iPhone 12 mini, iOS 16.

bartekpacia avatar Aug 04 '23 14:08 bartekpacia

My app uses the (currently) latest Flutter 3.10.6, and I'm also experiencing this error after I go to home and then go back to the app. iPhone 12 mini, iOS 16.

@bartekpacia Did you by any chance find a solution?

nicklbaert avatar Nov 06 '23 19:11 nicklbaert

Nope, there's no solution. This package has a bug that has to be fixed.

bartekpacia avatar Nov 06 '23 20:11 bartekpacia

Same problem here. Have been using this library for a long time without problems but now I've received in sentry a lot of events for this bug. EDIT: I'm using cached_network_image & blurhash.

senenpalanca97 avatar Nov 07 '23 11:11 senenpalanca97

Same problem here. Have been using this library for a long time without problems but now I've received in sentry a lot of events for this bug. EDIT: I'm using cached_network_image & blurhash.

Use BlurHashImage instead of. It worked for me

Before: BlurHash(hash: userProfile.mainPhotoBlurhash)

After: Image( image: BlurHashImage(userProfile.mainPhotoBlurhash), fit: BoxFit.cover, )

kienvtqhi avatar Jan 10 '24 09:01 kienvtqhi

Hello I have the same problem with flutter 3.16.8, it happened since the last update of the package with octo set and the extensions

JavierPerezLavadie avatar Jan 24 '24 13:01 JavierPerezLavadie