Skip to content

Commit

Permalink
Make dispose a no-op on HTML backend (flutter#35835)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield authored Aug 31, 2022
1 parent 86a2c93 commit 9d9d89a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/web_ui/lib/src/engine/text/canvas_paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ class CanvasParagraph implements ui.Paragraph {

@override
void dispose() {
spans.clear();
plainText = '';
// TODO(dnfield): It should be possible to clear resources here, but would
// need refcounting done on any surfaces/pictures holding references to this
// object.
_disposed = true;
}

Expand All @@ -270,7 +271,7 @@ class CanvasParagraph implements ui.Paragraph {
if (assertionsEnabled) {
return _disposed;
}
throw StateError('Vertices.debugDisposed is only avialalbe when asserts are enabled.');
throw StateError('Paragraph.debugDisposed is only avialalbe when asserts are enabled.');
}
}

Expand Down
21 changes: 21 additions & 0 deletions lib/web_ui/test/text/canvas_paragraph_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,27 @@ Future<void> testMain() async {
expect(paragraph.width, 30);
expect(paragraph.height, 10);
});

test('Render after dispose', () {
final ui.Paragraph paragraph = plain(ahemStyle, 'abc');
paragraph.layout(const ui.ParagraphConstraints(width: 30.8));

final ui.PictureRecorder recorder = ui.PictureRecorder();
final ui.Canvas canvas = ui.Canvas(recorder);
canvas.drawParagraph(paragraph, ui.Offset.zero);
final ui.Picture picture = recorder.endRecording();

paragraph.dispose();

final ui.SceneBuilder builder = ui.SceneBuilder();
builder.addPicture(ui.Offset.zero, picture);
final ui.Scene scene = builder.build();

ui.window.render(scene);

picture.dispose();
scene.dispose();
});
}

/// Shortcut to create a [ui.TextBox] with an optional [ui.TextDirection].
Expand Down

0 comments on commit 9d9d89a

Please sign in to comment.