From 6a2c7ed9dce500707fac7b6a6af53e83b4c28128 Mon Sep 17 00:00:00 2001 From: Ferhat Date: Wed, 26 Aug 2020 11:19:07 -0700 Subject: [PATCH] Guard recording_canvas against restore calls without ending recording (flutter/engine#20786) --- .../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/engine/src/flutter/lib/web_ui/lib/src/engine/html/recording_canvas.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/html/recording_canvas.dart index a7c994990a..55564b5fbf 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/html/recording_canvas.dart +++ b/engine/src/flutter/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/engine/src/flutter/lib/web_ui/test/engine/recording_canvas_test.dart b/engine/src/flutter/lib/web_ui/test/engine/recording_canvas_test.dart index 7bd1a9810e..e18309bae5 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/recording_canvas_test.dart +++ b/engine/src/flutter/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