未验证 提交 f8c8f27f 编写于 作者: J Jason Simmons 提交者: GitHub

Propagate image decode errors to the future returned by Codec.getNextFrame (#24336)

上级 0fa87b46
......@@ -1939,12 +1939,13 @@ class Codec extends NativeFieldWrapperClass2 {
final Completer<FrameInfo> completer = Completer<FrameInfo>.sync();
final String? error = _getNextFrame((_Image? image, int durationMilliseconds) {
if (image == null) {
throw Exception('Codec failed to produce an image, possibly due to invalid image data.');
completer.completeError(Exception('Codec failed to produce an image, possibly due to invalid image data.'));
} else {
completer.complete(FrameInfo._(
image: Image._(image),
duration: Duration(milliseconds: durationMilliseconds),
));
}
completer.complete(FrameInfo._(
image: Image._(image),
duration: Duration(milliseconds: durationMilliseconds),
));
});
if (error != null) {
throw Exception(error);
......
......@@ -34,6 +34,18 @@ void main() {
);
});
test('getNextFrame fails with invalid data', () async {
Uint8List data = await _getSkiaResource('flutter_logo.jpg').readAsBytes();
data = Uint8List.view(data.buffer, 0, 4000);
final ui.Codec codec = await ui.instantiateImageCodec(data);
try {
await codec.getNextFrame();
fail('exception not thrown');
} catch(e) {
expect(e, exceptionWithMessage('Codec failed'));
}
});
test('nextFrame', () async {
final Uint8List data = await _getSkiaResource('test640x479.gif').readAsBytes();
final ui.Codec codec = await ui.instantiateImageCodec(data);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册