From 4f2970b83aa3d090adb079f670c0c089556419c3 Mon Sep 17 00:00:00 2001 From: Julian Rex Date: Tue, 15 May 2018 22:27:39 -0400 Subject: [PATCH] Removed implicit retain. Adjusted multiple snapshot for snapshotter retention & lat/lon path. --- platform/darwin/src/MGLMapSnapshotter.mm | 2 +- .../Snapshotter Tests/MGLMapSnapshotterTest.m | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/platform/darwin/src/MGLMapSnapshotter.mm b/platform/darwin/src/MGLMapSnapshotter.mm index 0e13b98b6fc..a102d350942 100644 --- a/platform/darwin/src/MGLMapSnapshotter.mm +++ b/platform/darwin/src/MGLMapSnapshotter.mm @@ -150,7 +150,7 @@ - (void)startWithQueue:(dispatch_queue_t)queue completionHandler:(MGLMapSnapshot #endif [strongSelf drawAttributedSnapshot:attributions snapshotImage:mglImage pointForFn:pointForFn queue:queue completionHandler:completion]; } - _snapshotCallback = NULL; + strongSelf->_snapshotCallback = NULL; }); // Launches snapshot on background Thread owned by mbglMapSnapshotter diff --git a/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterTest.m b/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterTest.m index a1a63e40a66..2d491ab248a 100644 --- a/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterTest.m +++ b/platform/ios/Integration Tests/Snapshotter Tests/MGLMapSnapshotterTest.m @@ -194,11 +194,17 @@ - (void)testMultipleSnapshotters { for (size_t run = 0; run < numSnapshots; run++) { float ratio = (float)run/(float)numSnapshots; - float latlon = (ratio*30.0) + ((1-ratio)*40.0); - CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(latlon, latlon); + float lon = (ratio*120.0) + ((1.0-ratio)*54.0); + CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(57.0, lon); - MGLMapSnapshotter *snapshotter = snapshotterWithCoordinates(coord, size); - XCTAssertNotNil(snapshotter); + __block MGLMapSnapshotter *snapshotter; + + // Allocate from an autorelease pool here, to avoid having + // snapshotter retained for longer than we'd like to test. + @autoreleasepool { + snapshotter = snapshotterWithCoordinates(coord, size); + XCTAssertNotNil(snapshotter); + } [snapshotter startWithCompletionHandler:^(MGLMapSnapshot * _Nullable snapshot, NSError * _Nullable error) { @@ -216,6 +222,13 @@ - (void)testMultipleSnapshotters { XCTAttachment *attachment = [XCTAttachment attachmentWithImage:snapshot.image]; attachment.lifetime = XCTAttachmentLifetimeKeepAlways; [strongself addAttachment:attachment]; + + // Dealloc the snapshotter (by having this line in the block, we + // also retained the snapshotter. Setting to nil should release, as + // this block should be the only thing retaining it (since it was + // allocated from the above autorelease pool) + snapshotter = nil; + [expectation fulfill]; }]; } // end for loop