diff --git a/engine/src/flutter/lib/ui/painting/single_frame_codec.cc b/engine/src/flutter/lib/ui/painting/single_frame_codec.cc index 0298215767..ce1f6fc91c 100644 --- a/engine/src/flutter/lib/ui/painting/single_frame_codec.cc +++ b/engine/src/flutter/lib/ui/painting/single_frame_codec.cc @@ -33,6 +33,9 @@ Dart_Handle SingleFrameCodec::getNextFrame(Dart_Handle callback_handle) { } if (status_ == Status::kComplete) { + if (!cached_image_->image()) { + return tonic::ToDart("Decoded image has been disposed"); + } tonic::DartInvoke(callback_handle, {tonic::ToDart(cached_image_), tonic::ToDart(0)}); return Dart_Null(); diff --git a/engine/src/flutter/testing/dart/codec_test.dart b/engine/src/flutter/testing/dart/codec_test.dart index 86ce31a8d6..f06a5e4134 100644 --- a/engine/src/flutter/testing/dart/codec_test.dart +++ b/engine/src/flutter/testing/dart/codec_test.dart @@ -85,6 +85,20 @@ void main() { [0, 240, 246], ])); }); + + test('disposed decoded image', () async { + Uint8List data = await _getSkiaResource('flutter_logo.jpg').readAsBytes(); + final ui.Codec codec = await ui.instantiateImageCodec(data); + final ui.FrameInfo frameInfo = await codec.getNextFrame(); + expect(frameInfo.image, isNotNull); + frameInfo.image.dispose(); + try { + await codec.getNextFrame(); + fail('exception not thrown'); + } on Exception catch (e) { + expect(e.toString(), contains('Decoded image has been disposed')); + } + }); } /// Returns a File handle to a file in the skia/resources directory. diff --git a/engine/src/flutter/testing/dart/image_dispose_test.dart b/engine/src/flutter/testing/dart/image_dispose_test.dart index d1c1d308cd..fe0d11fda8 100644 --- a/engine/src/flutter/testing/dart/image_dispose_test.dart +++ b/engine/src/flutter/testing/dart/image_dispose_test.dart @@ -114,18 +114,6 @@ void main() { expect(frame2.image.isCloneOf(frame.image), false); }); - test('getNextFrame does not return a disposed image', () async { - final Uint8List bytes = await readFile('2x2.png'); - final Codec codec = await instantiateImageCodec(bytes); - final FrameInfo frame = await codec.getNextFrame(); - - frame.image.dispose(); - - final FrameInfo frame2 = await codec.getNextFrame(); - expect(frame2.image.clone()..dispose(), isNotNull); - frame2.image.dispose(); - }); - test('debugDisposed works', () async { final Uint8List bytes = await readFile('2x2.png'); final Codec codec = await instantiateImageCodec(bytes);