summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-03-14 20:55:37 -0400
committerFabian Guerra <fabian.guerra@mapbox.com>2018-03-16 18:24:14 -0400
commit4a3ee0e93d56bd8ad312e78e13193c9ab7716cd1 (patch)
tree4b8de45769863d0696057243e58eef1d34d3b5eb
parent51e8894352253b49b05bd5bd2cfc309f6b9bb20e (diff)
downloadqtlocation-mapboxgl-upstream/fabian-interpolation-crash-11431.tar.gz
[ios, macos] Fix a crash for cubic interpolated functions when the parameter is an array.upstream/fabian-interpolation-crash-11431
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm11
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm20
2 files changed, 27 insertions, 4 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index 62fddd8f86..b5319ec45e 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -716,7 +716,16 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
id base = [self.arguments[1] mgl_jsonExpressionObject];
[interpolationArray addObject:base];
} else if ([curveType isEqualToString:@"cubic-bezier"]) {
- NSArray *controlPoints = [self.arguments[1].collection mgl_jsonExpressionObject];
+ NSMutableArray *controlPoints = [NSMutableArray array];
+
+ if (self.arguments[1].expressionType == NSAggregateExpressionType) {
+ controlPoints = [self.arguments[1].collection mgl_jsonExpressionObject];
+ } else {
+ for (id expression in self.arguments[1].constantValue) {
+ [controlPoints addObject:[expression mgl_jsonExpressionObject]];
+ }
+ }
+
[interpolationArray addObjectsFromArray:controlPoints];
}
NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"interpolate", interpolationArray, self.operand.mgl_jsonExpressionObject, nil];
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index c317ed2858..7737787c9a 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -591,16 +591,30 @@ using namespace std::string_literals;
NSDictionary *stops = @{@0: MGLConstantExpression(@0), @100: MGLConstantExpression(@100)};
NSArray *parameters = @[ @0.42, @0, @0.58, @1 ];
NSExpression *expression = [NSExpression expressionWithFormat:@"FUNCTION(x, 'mgl_interpolateWithCurveType:parameters:stops:', 'cubic-bezier', { 0.42, 0, 0.58, 1 }, %@)", stops];
- NSExpression *aggregate = [NSExpression expressionForAggregate:@[[NSExpression expressionForConstantValue:@0.42], [NSExpression expressionForConstantValue:@0], [NSExpression expressionForConstantValue:@0.85], [NSExpression expressionForConstantValue:@1]]];
+ NSExpression *aggregate = [NSExpression expressionForAggregate:@[[NSExpression expressionForConstantValue:@0.42], [NSExpression expressionForConstantValue:@0], [NSExpression expressionForConstantValue:@0.58], [NSExpression expressionForConstantValue:@1]]];
NSExpression *interpolateExpression = [NSExpression mgl_expressionForInterpolateFunction:[NSExpression expressionForKeyPath:@"x"]
curveType:MGLExpressionInterpolationModeCubicBezier
parameters:aggregate
steps:[NSExpression expressionWithFormat:@"%@", stops]];
NSArray *jsonExpression = @[@"interpolate", @[@"cubic-bezier", @0.42, @0, @0.58, @1], @[@"get", @"x"], @0, @0, @100, @100];
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
-// XCTAssertEqualObjects(interpolateExpression.mgl_jsonExpressionObject, jsonExpression);
+ XCTAssertEqualObjects(interpolateExpression.mgl_jsonExpressionObject, jsonExpression);
+ XCTAssertEqualObjects([NSExpression mgl_expressionWithJSONObject:jsonExpression], expression);
+ XCTAssertEqualObjects([NSExpression mgl_expressionWithJSONObject:jsonExpression], interpolateExpression);
+ }
+ {
+ NSDictionary *stops = @{@0: MGLConstantExpression(@0), @100: MGLConstantExpression(@100)};
+ NSArray *parameters = @[ @0.42, @0, @0.58, @1 ];
+ NSExpression *expression = [NSExpression expressionWithFormat:@"FUNCTION(x, 'mgl_interpolateWithCurveType:parameters:stops:', 'cubic-bezier', { 0.42, 0, 0.58, 1 }, %@)", stops];
+ NSExpression *interpolateExpression = [NSExpression mgl_expressionForInterpolateFunction:[NSExpression expressionForKeyPath:@"x"]
+ curveType:MGLExpressionInterpolationModeCubicBezier
+ parameters:[NSExpression expressionWithFormat:@"%@", parameters]
+ steps:[NSExpression expressionWithFormat:@"%@", stops]];
+ NSArray *jsonExpression = @[@"interpolate", @[@"cubic-bezier", @0.42, @0, @0.58, @1], @[@"get", @"x"], @0, @0, @100, @100];
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+ XCTAssertEqualObjects(interpolateExpression.mgl_jsonExpressionObject, jsonExpression);
XCTAssertEqualObjects([NSExpression mgl_expressionWithJSONObject:jsonExpression], expression);
-// XCTAssertEqualObjects([NSExpression mgl_expressionWithJSONObject:jsonExpression], interpolateExpression);
+ XCTAssertNotEqualObjects([NSExpression mgl_expressionWithJSONObject:jsonExpression], interpolateExpression);
}
{
NSDictionary *stops = @{@0: MGLConstantExpression(@111), @1: MGLConstantExpression(@1111)};