summaryrefslogtreecommitdiff
path: root/platform/macos/app/MapDocument.m
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2018-04-24 20:32:43 -0400
committerJason Wray <jason@mapbox.com>2018-04-27 18:06:42 -0400
commit5a147f6335314defeed26c570ebcfe217e2af5d9 (patch)
tree05cc2ba8a7a65053baff045fe11801533a9d1a16 /platform/macos/app/MapDocument.m
parent4f7999fd1cec34e9beaf130d30897548d8dbca4a (diff)
downloadqtlocation-mapboxgl-5a147f6335314defeed26c570ebcfe217e2af5d9.tar.gz
[ios, macos] Fix possible retain cycles in blocks
Prompted by enabling CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF.
Diffstat (limited to 'platform/macos/app/MapDocument.m')
-rw-r--r--platform/macos/app/MapDocument.m24
1 files changed, 15 insertions, 9 deletions
diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m
index 9b18dbd761..aee14c5c2f 100644
--- a/platform/macos/app/MapDocument.m
+++ b/platform/macos/app/MapDocument.m
@@ -93,9 +93,8 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
BOOL _isTouringWorld;
BOOL _isShowingPolygonAndPolylineAnnotations;
BOOL _isShowingAnimatedAnnotation;
-
- // Snapshotter
- MGLMapSnapshotter* snapshotter;
+
+ MGLMapSnapshotter *_snapshotter;
}
#pragma mark Lifecycle
@@ -185,17 +184,23 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
options.zoomLevel = self.mapView.zoomLevel;
// Create and start the snapshotter
- snapshotter = [[MGLMapSnapshotter alloc] initWithOptions:options];
- [snapshotter startWithCompletionHandler:^(MGLMapSnapshot *snapshot, NSError *error) {
+ __weak __typeof__(self) weakSelf = self;
+ _snapshotter = [[MGLMapSnapshotter alloc] initWithOptions:options];
+ [_snapshotter startWithCompletionHandler:^(MGLMapSnapshot *snapshot, NSError *error) {
+ __typeof__(self) strongSelf = weakSelf;
+ if (!strongSelf) {
+ return;
+ }
+
if (error) {
NSLog(@"Could not load snapshot: %@", error.localizedDescription);
} else {
// Set the default name for the file and show the panel.
NSSavePanel *panel = [NSSavePanel savePanel];
- panel.nameFieldStringValue = [self.mapView.styleURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingPathExtension:@"png"];
+ panel.nameFieldStringValue = [strongSelf.mapView.styleURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingPathExtension:@"png"];
panel.allowedFileTypes = [@[(NSString *)kUTTypePNG] arrayByAddingObjectsFromArray:[NSBitmapImageRep imageUnfilteredTypes]];
- [panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
+ [panel beginSheetModalForWindow:strongSelf.window completionHandler:^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton) {
// Write the contents in the new format.
NSURL *fileURL = panel.URL;
@@ -232,7 +237,8 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
}];
}
- snapshotter = nil;
+
+ strongSelf->_snapshotter = nil;
}];
}
@@ -1179,7 +1185,7 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
return YES;
}
if (menuItem.action == @selector(takeSnapshot:)) {
- return !(snapshotter && [snapshotter isLoading]);
+ return !(_snapshotter && [_snapshotter isLoading]);
}
return NO;
}