mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Assert against infinite values of control points in CatmullRomSpline (#131820)
When providing infinite values for the control points of CatmullRomSpline, a StackOverflowError occurs. This asserts against that and provides a helpful error message. Fixes https://github.com/flutter/flutter/issues/131246
This commit is contained in:
parent
0ad45f2421
commit
b3a4decda6
@ -705,6 +705,27 @@ class CatmullRomSpline extends Curve2D {
|
|||||||
Offset? startHandle,
|
Offset? startHandle,
|
||||||
Offset? endHandle,
|
Offset? endHandle,
|
||||||
}) {
|
}) {
|
||||||
|
assert(
|
||||||
|
startHandle == null || startHandle.isFinite,
|
||||||
|
'The provided startHandle of CatmullRomSpline must be finite. The '
|
||||||
|
'startHandle given was $startHandle.'
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
endHandle == null || endHandle.isFinite,
|
||||||
|
'The provided endHandle of CatmullRomSpline must be finite. The endHandle '
|
||||||
|
'given was $endHandle.'
|
||||||
|
);
|
||||||
|
assert(() {
|
||||||
|
for (int index = 0; index < controlPoints.length; index++) {
|
||||||
|
if (!controlPoints[index].isFinite) {
|
||||||
|
throw FlutterError(
|
||||||
|
'The provided CatmullRomSpline control point at index $index is not '
|
||||||
|
'finite. The control point given was ${controlPoints[index]}.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}());
|
||||||
// If not specified, select the first and last control points (which are
|
// If not specified, select the first and last control points (which are
|
||||||
// handles: they are not intersected by the resulting curve) so that they
|
// handles: they are not intersected by the resulting curve) so that they
|
||||||
// extend the first and last segments, respectively.
|
// extend the first and last segments, respectively.
|
||||||
|
@ -305,6 +305,28 @@ void main() {
|
|||||||
expect(() {
|
expect(() {
|
||||||
CatmullRomSpline(const <Offset>[Offset.zero, Offset.zero, Offset.zero, Offset.zero], tension: 2.0);
|
CatmullRomSpline(const <Offset>[Offset.zero, Offset.zero, Offset.zero, Offset.zero], tension: 2.0);
|
||||||
}, throwsAssertionError);
|
}, throwsAssertionError);
|
||||||
|
expect(() {
|
||||||
|
CatmullRomSpline(
|
||||||
|
const <Offset>[Offset(double.infinity, 0.0), Offset.zero, Offset.zero, Offset.zero],
|
||||||
|
).generateSamples();
|
||||||
|
}, throwsAssertionError);
|
||||||
|
expect(() {
|
||||||
|
CatmullRomSpline(
|
||||||
|
const <Offset>[Offset(0.0, double.infinity), Offset.zero, Offset.zero, Offset.zero],
|
||||||
|
).generateSamples();
|
||||||
|
}, throwsAssertionError);
|
||||||
|
expect(() {
|
||||||
|
CatmullRomSpline(
|
||||||
|
startHandle: const Offset(0.0, double.infinity),
|
||||||
|
const <Offset>[Offset.zero, Offset.zero, Offset.zero, Offset.zero],
|
||||||
|
).generateSamples();
|
||||||
|
}, throwsAssertionError);
|
||||||
|
expect(() {
|
||||||
|
CatmullRomSpline(
|
||||||
|
endHandle: const Offset(0.0, double.infinity),
|
||||||
|
const <Offset>[Offset.zero, Offset.zero, Offset.zero, Offset.zero],
|
||||||
|
).generateSamples();
|
||||||
|
}, throwsAssertionError);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('CatmullRomSpline interpolates values properly when precomputed', () {
|
test('CatmullRomSpline interpolates values properly when precomputed', () {
|
||||||
@ -353,6 +375,24 @@ void main() {
|
|||||||
expect(() {
|
expect(() {
|
||||||
CatmullRomSpline.precompute(const <Offset>[Offset.zero, Offset.zero, Offset.zero, Offset.zero], tension: 2.0);
|
CatmullRomSpline.precompute(const <Offset>[Offset.zero, Offset.zero, Offset.zero, Offset.zero], tension: 2.0);
|
||||||
}, throwsAssertionError);
|
}, throwsAssertionError);
|
||||||
|
expect(() {
|
||||||
|
CatmullRomSpline.precompute(const <Offset>[Offset(double.infinity, 0.0), Offset.zero, Offset.zero, Offset.zero]);
|
||||||
|
}, throwsAssertionError);
|
||||||
|
expect(() {
|
||||||
|
CatmullRomSpline.precompute(const <Offset>[Offset(0.0, double.infinity), Offset.zero, Offset.zero, Offset.zero]);
|
||||||
|
}, throwsAssertionError);
|
||||||
|
expect(() {
|
||||||
|
CatmullRomSpline.precompute(
|
||||||
|
startHandle: const Offset(0.0, double.infinity),
|
||||||
|
const <Offset>[Offset.zero, Offset.zero, Offset.zero, Offset.zero],
|
||||||
|
);
|
||||||
|
}, throwsAssertionError);
|
||||||
|
expect(() {
|
||||||
|
CatmullRomSpline.precompute(
|
||||||
|
endHandle: const Offset(0.0, double.infinity),
|
||||||
|
const <Offset>[Offset.zero, Offset.zero, Offset.zero, Offset.zero],
|
||||||
|
);
|
||||||
|
}, throwsAssertionError);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('CatmullRomCurve interpolates given points correctly', () {
|
test('CatmullRomCurve interpolates given points correctly', () {
|
||||||
|
Loading…
Reference in New Issue
Block a user