diff --git a/engine/src/flutter/lib/ui/geometry.dart b/engine/src/flutter/lib/ui/geometry.dart index e96ff4cc27..3bd313ec11 100644 --- a/engine/src/flutter/lib/ui/geometry.dart +++ b/engine/src/flutter/lib/ui/geometry.dart @@ -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 { diff --git a/engine/src/flutter/lib/ui/painting.dart b/engine/src/flutter/lib/ui/painting.dart index 7abeed2a8e..b675c1c2bd 100644 --- a/engine/src/flutter/lib/ui/painting.dart +++ b/engine/src/flutter/lib/ui/painting.dart @@ -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); }