Skip to content

Commit

Permalink
[vector_graphics] Revert leak tracker change (#8544)
Browse files Browse the repository at this point in the history
The leak tracker changes are causing runtime crashes because an object is disposed too eagerly. 

Fixes flutter/flutter#162486
  • Loading branch information
jonahwilliams authored Jan 31, 2025
1 parent c6fcb9b commit 65177cb
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 32 deletions.
4 changes: 4 additions & 0 deletions packages/vector_graphics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.17

* Reverts leaker tracker changes that caused runtime exceptions.

## 1.1.16

* Fixes some memory leaks by disposing undisposed `ImageInfo`, `ui.Picture` and `Picture`.
Expand Down
8 changes: 4 additions & 4 deletions packages/vector_graphics/lib/src/listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class FlutterVectorGraphicsListener extends VectorGraphicsCodecListener {
final List<_TextConfig> _textConfig = <_TextConfig>[];
final List<_TextPosition> _textPositions = <_TextPosition>[];
final List<Future<void>> _pendingImages = <Future<void>>[];
final Map<int, ImageInfo> _images = <int, ImageInfo>{};
final Map<int, Image> _images = <int, Image>{};
final Map<int, _PatternState> _patterns = <int, _PatternState>{};
Path? _currentPath;
Size _size = Size.zero;
Expand Down Expand Up @@ -283,7 +283,7 @@ class FlutterVectorGraphicsListener extends VectorGraphicsCodecListener {
try {
return PictureInfo._(_recorder.endRecording(), _size);
} finally {
for (final ImageInfo image in _images.values) {
for (final Image image in _images.values) {
image.dispose();
}
_images.clear();
Expand Down Expand Up @@ -746,7 +746,7 @@ class FlutterVectorGraphicsListener extends VectorGraphicsCodecListener {
listener = ImageStreamListener(
(ImageInfo image, bool synchronousCall) {
cacheCompleter.removeListener(listener);
_images[imageId] = image;
_images[imageId] = image.image;
completer.complete();
},
onError: (Object exception, StackTrace? stackTrace) {
Expand All @@ -773,7 +773,7 @@ class FlutterVectorGraphicsListener extends VectorGraphicsCodecListener {
@override
void onDrawImage(int imageId, double x, double y, double width, double height,
Float64List? transform) {
final Image image = _images[imageId]!.image;
final Image image = _images[imageId]!;
if (transform != null) {
_canvas.save();
_canvas.transform(transform);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ class RenderVectorGraphic extends RenderBox {

final ui.Image pending =
rasterPicture.toImageSync(scaledWidth, scaledHeight);
rasterPicture.dispose();
return RasterData(pending, 0, key);
}

Expand Down
8 changes: 3 additions & 5 deletions packages/vector_graphics/lib/src/vector_graphics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,8 @@ class _VectorGraphicWidgetState extends State<VectorGraphic> {
return;
}
data.count -= 1;
if (data.count == 0) {
if (_livePictureCache.containsKey(data.key)) {
_livePictureCache.remove(data.key);
}
if (data.count == 0 && _livePictureCache.containsKey(data.key)) {
_livePictureCache.remove(data.key);
data.pictureInfo.picture.dispose();
}
}
Expand Down Expand Up @@ -384,7 +382,7 @@ class _VectorGraphicWidgetState extends State<VectorGraphic> {
}

Future<void> _loadAssetBytes() async {
// First check if we have an available picture and use this immediately.
// First check if we have an avilable picture and use this immediately.
final Object loaderKey = widget.loader.cacheKey(context);
final _PictureKey key =
_PictureKey(loaderKey, locale, textDirection, widget.clipViewbox);
Expand Down
3 changes: 1 addition & 2 deletions packages/vector_graphics/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: vector_graphics
description: A vector graphics rendering package for Flutter using a binary encoding.
repository: https://github.com/flutter/packages/tree/main/packages/vector_graphics
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+vector_graphics%22
version: 1.1.16
version: 1.1.17

environment:
sdk: ^3.4.0
Expand All @@ -17,7 +17,6 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
leak_tracker_flutter_testing: any
vector_graphics_compiler: ^1.1.11+1

platforms:
Expand Down
13 changes: 0 additions & 13 deletions packages/vector_graphics/test/flutter_test_config.dart

This file was deleted.

10 changes: 3 additions & 7 deletions packages/vector_graphics/test/vector_graphics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,7 @@ void main() {
);
await tester.pumpAndSettle();

final PictureInfo picture = await completer.future;
addTearDown(picture.picture.dispose);
expect(picture, isA<PictureInfo>());
expect(await completer.future, isA<PictureInfo>());
expect(debugLastLocale, const Locale('fr', 'CH'));
expect(debugLastTextDirection, TextDirection.rtl);
});
Expand Down Expand Up @@ -477,9 +475,7 @@ void main() {
);
await tester.pumpAndSettle();

final PictureInfo picture = await completer.future;
addTearDown(picture.picture.dispose);
expect(picture, isA<PictureInfo>());
expect(await completer.future, isA<PictureInfo>());
expect(debugLastLocale, PlatformDispatcher.instance.locale);
expect(debugLastTextDirection, TextDirection.ltr);
});
Expand Down Expand Up @@ -588,7 +584,7 @@ void main() {
expect(imageCache.statusForKey(imageKey).live, false);
expect(imageCache.statusForKey(imageKey).keepAlive, true);

// A blue square, because the image is available now.
// A blue square, becuase the image is available now.
await expectLater(
find.byKey(key),
matchesGoldenFile('vg_with_image_blue.png'),
Expand Down

0 comments on commit 65177cb

Please sign in to comment.