From 43bcba4cbe2242d1c0aaefbdeed0906600589511 Mon Sep 17 00:00:00 2001 From: Julian Rex Date: Mon, 26 Feb 2018 11:11:27 -0500 Subject: [ios] Release only called if the layer is really being removed from the style. Update associated test that failed. --- platform/darwin/src/MGLStyleLayer.mm | 8 ++--- platform/darwin/test/MGLStyleTests.mm | 39 +++++++++++++++++----- .../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]; } -- cgit v1.2.1