diff options
author | Julian Rex <julian.rex@mapbox.com> | 2018-02-26 11:11:27 -0500 |
---|---|---|
committer | Andrew Kitchen <akitchen@gmail.com> | 2018-02-26 11:01:21 -0800 |
commit | 2a4d13b1e4aec8cf327a1d4cd9ded7d94bc697c7 (patch) | |
tree | a2c3162a5823ac3c662484c7fe9d42c2d2c8562a | |
parent | e4aaaa3c70b0f13bb2f2d315586e98d9525310d9 (diff) | |
download | qtlocation-mapboxgl-2a4d13b1e4aec8cf327a1d4cd9ded7d94bc697c7.tar.gz |
[ios] Release only called if the layer is really being removed from the style. Update associated test that failed.
-rw-r--r-- | platform/darwin/src/MGLStyleLayer.mm | 8 | ||||
-rw-r--r-- | platform/darwin/test/MGLStyleTests.mm | 39 | ||||
-rw-r--r-- | platform/ios/Integration Tests/MBGLIntegrationTests.m | 1 |
3 files changed, 35 insertions, 13 deletions
diff --git a/platform/darwin/src/MGLStyleLayer.mm b/platform/darwin/src/MGLStyleLayer.mm index 2a70cab563..45a4486525 100644 --- a/platform/darwin/src/MGLStyleLayer.mm +++ b/platform/darwin/src/MGLStyleLayer.mm @@ -54,11 +54,11 @@ { if (self.rawLayer == style.rawStyle->getLayer(self.identifier.UTF8String)) { _pendingLayer = style.rawStyle->removeLayer(self.identifier.UTF8String); - } - // Pair the retain above, and release self, since we're now removed from the collection - CFTypeRef toRelease = (__bridge CFTypeRef)self; - CFBridgingRelease(toRelease); + // Pair the retain above, and release self, since we're now removed from the collection + CFTypeRef toRelease = (__bridge CFTypeRef)self; + CFBridgingRelease(toRelease); + } } - (void)setVisible:(BOOL)visible diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index 8f610e338c..5ab17dd62e 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -359,20 +359,41 @@ } - (void)testAddingLayerOfTypeABeforeRemovingLayerOfTypeBWithSameIdentifier { - MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-identifier" shape:nil options:nil]; - [self.style addSource:source]; - // Add a fill layer - MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"some-identifier" source:source]; - [self.style addLayer:fillLayer]; + __weak MGLFillStyleLayer *weakFillLayer = nil; + __weak MGLLineStyleLayer *weakLineLayer = nil; - // Attempt to remove a line layer with the same identifier as the fill layer - MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:fillLayer.identifier source:source]; - [self.style removeLayer:lineLayer]; + @autoreleasepool { + + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-identifier" shape:nil options:nil]; + [self.style addSource:source]; + + // Add a fill layer + MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"some-identifier" source:source]; + weakFillLayer = fillLayer; + + [self.style addLayer:fillLayer]; - XCTAssertTrue([[self.style layerWithIdentifier:fillLayer.identifier] isMemberOfClass:[MGLFillStyleLayer class]]); + // Attempt to remove a line layer with the same identifier as the fill layer + MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:fillLayer.identifier source:source]; + weakLineLayer = lineLayer; + [self.style removeLayer:lineLayer]; + + // The above remove should fail, and the fill layer should still be there. + XCTAssertTrue([[self.style layerWithIdentifier:fillLayer.identifier] isMemberOfClass:[MGLFillStyleLayer class]]); + + // Finally remove the fill layer. + [self.style removeLayer:fillLayer]; + + fillLayer = nil; + lineLayer = nil; + } + + XCTAssertNil(weakFillLayer, @""); + XCTAssertNil(weakLineLayer, @""); } + - (NSString *)stringWithContentsOfStyleHeader { NSURL *styleHeaderURL = [[[NSBundle mgl_frameworkBundle].bundleURL URLByAppendingPathComponent:@"Headers" isDirectory:YES] diff --git a/platform/ios/Integration Tests/MBGLIntegrationTests.m b/platform/ios/Integration Tests/MBGLIntegrationTests.m index 941e73621f..1008ef6c9f 100644 --- a/platform/ios/Integration Tests/MBGLIntegrationTests.m +++ b/platform/ios/Integration Tests/MBGLIntegrationTests.m @@ -42,6 +42,7 @@ - (void)tearDown { _styleLoadingExpectation = nil; self.mapView = nil; + self.style = nil; [super tearDown]; } |