From ecba1da3c5f52f405337b7d6ee77b33570931f22 Mon Sep 17 00:00:00 2001 From: ferhatb Date: Wed, 26 Aug 2020 09:20:40 -0700 Subject: [PATCH] Guard recording_canvas against restore calls without ending recording --- lib/web_ui/lib/src/engine/html/recording_canvas.dart | 2 +- lib/web_ui/test/engine/recording_canvas_test.dart | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/web_ui/lib/src/engine/html/recording_canvas.dart b/lib/web_ui/lib/src/engine/html/recording_canvas.dart index a7c994990ad5d..55564b5fbfcaf 100644 --- a/lib/web_ui/lib/src/engine/html/recording_canvas.dart +++ b/lib/web_ui/lib/src/engine/html/recording_canvas.dart @@ -227,7 +227,7 @@ class RecordingCanvas { } void restore() { - if (!_recordingEnded) { + if (!_recordingEnded && _saveCount > 1) { _paintBounds.restoreTransformsAndClip(); } if (_commands.isNotEmpty && _commands.last is PaintSave) { diff --git a/lib/web_ui/test/engine/recording_canvas_test.dart b/lib/web_ui/test/engine/recording_canvas_test.dart index 7bd1a9810eef4..e18309bae51f5 100644 --- a/lib/web_ui/test/engine/recording_canvas_test.dart +++ b/lib/web_ui/test/engine/recording_canvas_test.dart @@ -200,6 +200,13 @@ void testMain() { // Should not throw exception on restore. expect(() => rc.restore(), returnsNormally); }); + + // Regression test for https://github.com/flutter/flutter/issues/61697. + test('Allows restore calls even if recording is not ended', () { + final RecordingCanvas rc = RecordingCanvas(Rect.fromLTRB(0, 0, 200, 400)); + // Should not throw exception on restore. + expect(() => rc.restore(), returnsNormally); + }); } // Expect a drawDRRect call to be registered in the mock call log, with the expectedArguments