diff options
author | Julian Rex <julian.rex@mapbox.com> | 2018-03-22 19:36:43 -0400 |
---|---|---|
committer | Julian Rex <julian.rex@mapbox.com> | 2018-03-22 19:36:43 -0400 |
commit | f303d64a3a2bdbdb3011e94ae7c5333697c983d0 (patch) | |
tree | 754188bc3e417cdc4e97f9852eb6acb4d593a9ee | |
parent | 7556299851d8ba7067500369545af4d2aa5b4c77 (diff) | |
download | qtlocation-mapboxgl-f303d64a3a2bdbdb3011e94ae7c5333697c983d0.tar.gz |
WIP - Reordered lines in testOpenGLLayerDoesNotLeakWhenStyleChanged test, and forced a fail.
-rw-r--r-- | platform/darwin/src/MGLOpenGLStyleLayer.h | 2 | ||||
-rw-r--r-- | platform/darwin/src/MGLOpenGLStyleLayer.mm | 10 | ||||
-rw-r--r-- | platform/ios/Integration Tests/MBGLIntegrationTests.mm | 41 | ||||
-rw-r--r-- | src/mbgl/style/layers/custom_layer.cpp | 1 |
4 files changed, 35 insertions, 19 deletions
diff --git a/platform/darwin/src/MGLOpenGLStyleLayer.h b/platform/darwin/src/MGLOpenGLStyleLayer.h index 52173786f7..ad854eac4d 100644 --- a/platform/darwin/src/MGLOpenGLStyleLayer.h +++ b/platform/darwin/src/MGLOpenGLStyleLayer.h @@ -19,7 +19,7 @@ MGL_EXPORT @property (nonatomic, unsafe_unretained, nullable) void *owner; - (instancetype)initWithLayer:(MGLStyleLayer*)styleLayer; - (void)retainLayer; -- (void)weakenLayer; +- (void)releaseLayer; @end diff --git a/platform/darwin/src/MGLOpenGLStyleLayer.mm b/platform/darwin/src/MGLOpenGLStyleLayer.mm index 2b638e2067..ad41958903 100644 --- a/platform/darwin/src/MGLOpenGLStyleLayer.mm +++ b/platform/darwin/src/MGLOpenGLStyleLayer.mm @@ -18,7 +18,7 @@ NSLog(@"LayerRetainer dealloc start %p", self); while (self.layerRetainCount) { - [self weakenLayer]; + [self releaseLayer]; } NSLog(@"LayerRetainer dealloc end %p", self); @@ -60,11 +60,11 @@ } self.layerRetainCount++; - NSLog(@"LayerRetainer %p strengthen %ld", self, self.layerRetainCount); + NSLog(@"LayerRetainer %p retained %ld", self, self.layerRetainCount); } -- (void)weakenLayer { +- (void)releaseLayer { if (!self.layer) return; @@ -76,7 +76,7 @@ CFBridgingRelease((__bridge CFTypeRef)self.layer); } - NSLog(@"LayerRetainer %p weaken %ld", self, self.layerRetainCount); + NSLog(@"LayerRetainer %p released %ld", self, self.layerRetainCount); } @end @@ -92,7 +92,7 @@ void MGLCustomLayerContextAttachFunction(void *context) { void MGLCustomLayerContextDetachFunction(void *context) { MGLOpenGLStyleLayerRetainer *contextRetainer = (__bridge MGLOpenGLStyleLayerRetainer*)context; - [contextRetainer weakenLayer]; + [contextRetainer releaseLayer]; } diff --git a/platform/ios/Integration Tests/MBGLIntegrationTests.mm b/platform/ios/Integration Tests/MBGLIntegrationTests.mm index 2e01ce8ca2..449adb5dbc 100644 --- a/platform/ios/Integration Tests/MBGLIntegrationTests.mm +++ b/platform/ios/Integration Tests/MBGLIntegrationTests.mm @@ -68,7 +68,7 @@ - (void)waitForMapViewToBeRendered { [self.mapView setNeedsGLDisplay]; _renderFinishedExpectation = [self expectationWithDescription:@"Map view should be rendered"]; - [self waitForExpectations:@[_renderFinishedExpectation] timeout:1]; + [self waitForExpectations:@[_renderFinishedExpectation] timeout:10000]; } - (void)waitForManagedLayersToExpire { @@ -515,29 +515,44 @@ [self.style insertLayer:layer atIndex:0]; layer = nil; } - // Unlike other MGLStyleLayers, MGLOpenGLStyleLayers are managed for retain/release purposes - XCTAssertNotNil(weakLayer); + } - [self waitForMapViewToBeRendered]; + // Unlike other MGLStyleLayers, MGLOpenGLStyleLayers are managed for retain/release purposes + XCTAssertNotNil(weakLayer); + + [self waitForMapViewToBeRendered]; + + // should be identical to the original + MGLStyleLayer *layer2 = [self.mapView.style layerWithIdentifier:@"gl-layer"]; + + + NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; + _styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; + [self.mapView setStyleURL:styleURL]; + [self waitForExpectations:@[_styleLoadingExpectation] timeout:10]; + + // At this point the C++ CustomLayer will have been destroyed, BUT we're holding on + // to the obj-c layer. We don't currently clear the rawLayer, so it could now be + // pointing at garbage. And the following line will crash (due to description + // using .rawLayer) + +// (void)layer2; + XCTFail(); +// [self.style insertLayer:layer2 atIndex:0]; - NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; - _styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; - [self.mapView setStyleURL:styleURL]; - [self waitForExpectations:@[_styleLoadingExpectation] timeout:10]; - } [self waitForManagedLayersToExpire]; // Asking the style for the layer should return nil - MGLStyleLayer *layer2 = [self.mapView.style layerWithIdentifier:@"gl-layer"]; - XCTAssertNil(layer2); - XCTAssertNil(weakLayer); + MGLStyleLayer *layer3 = [self.mapView.style layerWithIdentifier:@"gl-layer"]; + XCTAssertNil(layer3); +// XCTAssertNil(weakLayer); } - (void)testOpenGLLayerDoesNotLeakWhenMapViewDeallocs { __weak id weakLayer; - + @autoreleasepool { NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; diff --git a/src/mbgl/style/layers/custom_layer.cpp b/src/mbgl/style/layers/custom_layer.cpp index 3198173412..234aa13b83 100644 --- a/src/mbgl/style/layers/custom_layer.cpp +++ b/src/mbgl/style/layers/custom_layer.cpp @@ -9,6 +9,7 @@ CustomLayer::~CustomLayer() { printf("~CustomLayer destructor %p\n", this); + // Need to set rawLayer to nil in the obj-c layer. } CustomLayer::CustomLayer(const std::string& layerID, |