flutter_cached_network_image icon indicating copy to clipboard operation
flutter_cached_network_image copied to clipboard

Decoded image has been disposed

Open thiagocarvalhodev opened this issue 2 years ago • 4 comments

🐛 Bug Report

Expected behavior

Should load the image correctly.

Reproduction steps

I'm checking how much memory is currently in the cache and then cleaning the cache when full.

I'm receiving the following logs on Crashlytics:

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Exception: Decoded image has been disposed. Error thrown null.
       at FirebaseCrashlytics.recordError(firebase_crashlytics.dart:119)
       at CustomExtendedImage.build.<fn>(custom_extended_image.dart:72)
       at CachedNetworkImage._octoErrorBuilder(cached_image_widget.dart:318)

Check the code:

void _checkMemory() {
    late int maxBytes;
    final ConfigProvider configProvider = locator<ConfigProvider>();
    if (Platform.isAndroid) {
      maxBytes = 1024 * 1024 * 100 * configProvider.androidMaxCache; // 500 MB
    } else {
      maxBytes = 1024 * 1024 * 100 * configProvider.iOSMaxCache; // 400 MB
    }
    FirebaseCrashlytics.instance
        .log('Max bytes in cache for images: ${maxBytes.toString()}');

    ImageCache _imageCache = PaintingBinding.instance.imageCache;
    if (_imageCache.currentSize >= 400 ||
        _imageCache.currentSizeBytes >= maxBytes) {
      FirebaseCrashlytics.instance.log(
          'Current image cache size: ${_imageCache.currentSizeBytes}. Its greater than the max: ${maxBytes.toString()} or greater than 400mb.\nCleaning images from cache.');

      _imageCache.clearLiveImages();
      _imageCache.clear();

      FirebaseCrashlytics.instance.log('Images removed from cache.');
      return;
    }
  }

  @override
  Widget build(BuildContext context) {
    final int? cacheWidthInt =
        cacheWidth ? MediaQuery.of(context).size.width.toInt() : null;
    final int? cacheHeightInt =
        cacheHeight ? MediaQuery.of(context).size.height.toInt() : null;
    _checkMemory();
    return CachedNetworkImage(
      imageUrl: url,
      fit: BoxFit.cover,
      height: height ?? MediaQuery.of(context).size.height,
      width: width ?? MediaQuery.of(context).size.width,
      placeholderFadeInDuration: Duration.zero,
      fadeInDuration: Duration.zero,
      fadeOutDuration: Duration.zero,
      errorWidget: (context, url, error) {
        FirebaseCrashlytics.instance.log(
          'An error occur loading image: $url\nShowing error placeholder.',
        );

        FirebaseCrashlytics.instance.recordError(error, null);

        return const Icon(Icons.error);
      },
      memCacheWidth: cacheWidth ? (cacheWidthInt! * 1.5).toInt() : null,
      color: color,
      filterQuality: FilterQuality.medium,
      memCacheHeight: cacheHeight ? (cacheHeightInt! * 1.4).toInt() : null,
    );
}

Configuration

Version: 3.2.3

Platform:

  • [x] :robot: Android

thiagocarvalhodev avatar Dec 01 '22 23:12 thiagocarvalhodev

Hello, I have the same error in android : Exception: Decoded image has been disposed.

flutter: 3.3.10 cached_network_image : 3.2.3

#0      Codec.getNextFrame (dart:ui/painting.dart:2002:7)
#1      MultiImageStreamCompleter._decodeNextFrameAndSchedule (package:cached_network_image/src/image_provider/multi_image_stream_completer.dart:127:34)
#2      MultiImageStreamCompleter.addListener (package:cached_network_image/src/image_provider/multi_image_stream_completer.dart:170:42)
#3      ImageStream.addListener (package:flutter/src/painting/image_stream.dart:373:26)
#4      _ImageState._listenToStream (package:flutter/src/widgets/image.dart:1209:19)
#5      _ImageState.didChangeDependencies (package:flutter/src/widgets/image.dart:1068:7)

Thanks for your help

mohachouch avatar Jan 04 '23 17:01 mohachouch

I'm facing the same issue. Not sure how to reproduce but I'm seeing some reports on the crashlytics tool we use

ggirotto avatar Oct 11 '23 16:10 ggirotto

flutter 3.10 cached_network_image 3.3.0

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Exception: Decoded image has been disposed. Error thrown resolving an image frame. at Codec.getNextFrame(dart:ui) at MultiImageStreamCompleter._decodeNextFrameAndSchedule(multi_image_stream_completer.dart:127) at MultiImageStreamCompleter.addListener(multi_image_stream_completer.dart:170) at ImageStream.addListener(image_stream.dart:376)

NSLogZfRee avatar Dec 08 '23 08:12 NSLogZfRee