Return an error if a SingleFrameCodec's cached decoded image has been disposed (flutter/engine#33819)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -85,6 +85,20 @@ void main() {
|
||||
<int>[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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user