Skip to content

Commit

Permalink
fix: TextBoxComponent's boxConfig timePerChar generates "Optimized Ou…
Browse files Browse the repository at this point in the history
…t" error #2143 (#2328)

Error was happening because cachedImage.dispose(); was called multiple times on the same object.

#2143
  • Loading branch information
fpv999 authored Feb 7, 2023
1 parent e0a4c07 commit 5874f60
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/flame/lib/src/components/text_box_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,20 @@ class TextBoxComponent<T extends TextRenderer> extends TextComponent {
}
}

final Set<Image> cachedToRemove = {};

Future<void> redraw() async {
final newSize = _recomputeSize();
final cachedImage = cache;
if (cachedImage != null) {
if (cachedImage != null && !cachedToRemove.contains(cachedImage)) {
cachedToRemove.add(cachedImage);
// Do not dispose of the cached image immediately, since it may have been
// sent into the rendering pipeline where it is still pending to be used.
// See issue #1618 for details.
Future.delayed(const Duration(milliseconds: 100), cachedImage.dispose);
Future.delayed(const Duration(milliseconds: 100), () {
cachedToRemove.remove(cachedImage);
cachedImage.dispose();
});
}
cache = await _fullRenderAsImage(newSize);
size = newSize;
Expand Down

0 comments on commit 5874f60

Please sign in to comment.