summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2018-04-05 23:45:45 -0400
committerJulian Rex <julian.rex@mapbox.com>2018-05-21 13:05:04 -0400
commit33a5b48367495cf458ad4923d641cb2495e6dbd3 (patch)
tree40596bd7f73aec8846008d47671db810160cec7e
parent3b61b5121739d66c0c84cc6911e504a10630ccbc (diff)
downloadqtlocation-mapboxgl-33a5b48367495cf458ad4923d641cb2495e6dbd3.tar.gz
Add test for setting shape source to nil from mapViewRegionIsChanging
-rw-r--r--platform/ios/Integration Tests/MBShapeSourceTests.m58
-rw-r--r--src/mbgl/map/transform.cpp8
2 files changed, 61 insertions, 5 deletions
diff --git a/platform/ios/Integration Tests/MBShapeSourceTests.m b/platform/ios/Integration Tests/MBShapeSourceTests.m
index 20a325af46..6a5c2942e4 100644
--- a/platform/ios/Integration Tests/MBShapeSourceTests.m
+++ b/platform/ios/Integration Tests/MBShapeSourceTests.m
@@ -13,7 +13,7 @@
@implementation MBShapeSourceTests
-- (void)testRepeatedlyChangingShapeSourceToNil {
+- (void)testSettingShapeSourceToNilInRegionDidChange {
NSMutableArray *features = [[NSMutableArray alloc] init];
@@ -38,7 +38,7 @@
XCTestExpectation *expectation = [self expectationWithDescription:@"regionDidChange expectation"];
__weak typeof(self) weakself = self;
- __block NSInteger delegateCallCount;
+ __block NSInteger delegateCallCount = 0;
self.regionDidChange = ^(MGLMapView *mapView, BOOL animated) {
@@ -56,7 +56,7 @@
// See https://github.com/mapbox/mapbox-gl-native/issues/11180
if (delegateCallCount > 10) {
- XCTFail();
+ TestFailWithSelf(strongSelf);
}
else {
shapeSource.shape = nil;
@@ -70,5 +70,57 @@
[self waitForExpectations:@[expectation] timeout:30.0];
}
+- (void)testSettingShapeSourceToNilInRegionIsChanging {
+
+ NSMutableArray *features = [[NSMutableArray alloc] init];
+
+ for (NSUInteger i = 0; i <= 180; i+=5) {
+ CLLocationCoordinate2D coord[4] = {
+ CLLocationCoordinate2DMake(round(0), round(i)),
+ CLLocationCoordinate2DMake(round(20), round(i)),
+ CLLocationCoordinate2DMake(round(0), round(i / 2 )),
+ CLLocationCoordinate2DMake(round(20), round(i / 2))};
+
+ MGLPolygonFeature *feature = [MGLPolygonFeature polygonWithCoordinates:coord count:4];
+ [features addObject:feature];
+ }
+
+ MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"source" features:features options:nil];
+ [self.style addSource:shapeSource];
+
+ MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"layer" source:shapeSource];
+ layer.fillOpacity = [NSExpression expressionForConstantValue:@0.5];
+ [self.style addLayer:layer];
+
+ XCTestExpectation *expectation = [self expectationWithDescription:@"regionDidChange expectation"];
+
+ __block NSInteger delegateCallCount = 0;
+ __weak typeof(self) weakself = self;
+
+ self.regionIsChanging = ^(MGLMapView *mapView) {
+ // Setting the shapeSource.shape = nil, was causing an infinite loop, so here
+ // we check for a runaway call. 10 here is arbitrary. We could argue that this
+ // should check that the call count is only 1, however in this case we particularly
+ // want to check for the infinite loop.
+ // See https://github.com/mapbox/mapbox-gl-native/issues/11180
+ shapeSource.shape = nil;
+ };
+
+ self.regionDidChange = ^(MGLMapView *mapView, BOOL animated) {
+
+ delegateCallCount++;
+
+ if (delegateCallCount > 1) {
+ TestFailWithSelf(weakself);
+ }
+
+ [NSObject cancelPreviousPerformRequestsWithTarget:expectation selector:@selector(fulfill) object:nil];
+ [expectation performSelector:@selector(fulfill) withObject:nil afterDelay:1.0];
+ };
+
+ [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(10.0, 10.0) animated:YES];
+ [self waitForExpectations:@[expectation] timeout:30.0];
+}
+
@end
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index f85272929f..07e54d33bd 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -628,8 +628,12 @@ bool Transform::inTransition() const {
}
void Transform::updateTransitions(const TimePoint& now) {
- if (transitionFrameFn) {
- transitionFrameFn(now);
+ auto transition = transitionFrameFn;
+ transitionFrameFn = nullptr;
+
+ if (transition) {
+ transition(now);
+ transitionFrameFn = transition;
}
}