Check if the canvas bounds rect contains infinite or NaN values (flutter/engine#3339)

See https://github.com/flutter/flutter/issues/7431
This commit is contained in:
Jason Simmons
2017-01-13 17:08:24 -08:00
committed by GitHub
parent 76a1339755
commit c42a2edc20
2 changed files with 5 additions and 0 deletions

View File

@@ -580,6 +580,9 @@ class Rect {
/// Negative areas are considered empty.
bool get isEmpty => left >= right || top >= bottom;
/// Whether all coordinates of this rectangle are finite.
bool get isFinite => left.isFinite && top.isFinite && right.isFinite && bottom.isFinite;
/// The lesser of the magnitudes of the width and the height of this
/// rectangle.
double get shortestSide {

View File

@@ -1116,6 +1116,8 @@ class Canvas extends NativeFieldWrapperClass2 {
throw new ArgumentError('The given PictureRecorder was null.');
if (recorder.isRecording)
throw new ArgumentError('The given PictureRecorder is already associated with another Canvas.');
if (!cullRect.isFinite)
throw new ArgumentError('The cullRect contains infinite or NaN coordinates.');
// TODO(ianh): throw if recorder is defunct (https://github.com/flutter/flutter/issues/2531)
_constructor(recorder, cullRect.left, cullRect.top, cullRect.right, cullRect.bottom);
}