Guard recording_canvas against restore calls without ending recording (flutter/engine#20786)

This commit is contained in:
Ferhat
2020-08-26 11:19:07 -07:00
committed by GitHub
parent e90eeda5ae
commit 6a2c7ed9dc
2 changed files with 8 additions and 1 deletions

View File

@@ -227,7 +227,7 @@ class RecordingCanvas {
}
void restore() {
if (!_recordingEnded) {
if (!_recordingEnded && _saveCount > 1) {
_paintBounds.restoreTransformsAndClip();
}
if (_commands.isNotEmpty && _commands.last is PaintSave) {

View File

@@ -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