Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Removed redundant loading property. Added (currently private) `canc…
Browse files Browse the repository at this point in the history
…elled` property.
  • Loading branch information
Julian Rex committed Aug 29, 2018
1 parent 56bd122 commit 323d4cb
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
3 changes: 0 additions & 3 deletions platform/darwin/src/MGLMapSnapshotter.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@ MGL_EXPORT
Once you call this method, you cannot resume the snapshot. In order to obtain
the snapshot, create a new `MGLMapSnapshotter` object.
The completion handler will be called with an `NSError` with domain
`MGLErrorDomain` and error code `MGLErrorCodeSnapshotUserCancelled`.
*/
- (void)cancel;

Expand Down
20 changes: 9 additions & 11 deletions platform/darwin/src/MGLMapSnapshotter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ - (CLLocationCoordinate2D)coordinateForPoint:(NSPoint)point
@end

@interface MGLMapSnapshotter()
@property (nonatomic) BOOL loading;
@property (nonatomic) BOOL cancelled;
@property (nonatomic) dispatch_queue_t resultQueue;
@property (nonatomic, copy) MGLMapSnapshotCompletionHandler completion;
+ (void)completeWithErrorCode:(MGLErrorCode)errorCode description:(nonnull NSString*)description onQueue:(dispatch_queue_t)queue completion:(MGLMapSnapshotCompletionHandler)completion;
Expand All @@ -122,8 +122,8 @@ @implementation MGLMapSnapshotter {
}

- (void)dealloc {
if (_snapshotCallback) {
NSAssert(_loading, @"Snapshot in progress - `loading` should = YES");
if (_completion) {
NSAssert(_snapshotCallback, @"Snapshot in progress - there should be a valid callback");

[MGLMapSnapshotter completeWithErrorCode:MGLErrorCodeSnapshotFailed
description:@"MGLMapSnapshotter deallocated prior to snapshot completion."
Expand All @@ -137,8 +137,6 @@ - (instancetype)initWithOptions:(MGLMapSnapshotOptions *)options
self = [super init];
if (self) {
[self setOptions:options];
_loading = false;

}
return self;
}
Expand All @@ -155,15 +153,15 @@ - (void)startWithQueue:(dispatch_queue_t)queue completionHandler:(MGLMapSnapshot
format:@"startWithQueue:completionHandler: must be called from a thread with an active run loop."];
}

if ([self isLoading]) {
if (self.completion) {
// Consider replacing this exception with an error passed to the completion block.
[NSException raise:NSInternalInconsistencyException
format:@"Already started this snapshotter."];
}

self.loading = true;

self.completion = completion;
self.resultQueue = queue;
self.cancelled = NO;

__weak __typeof__(self) weakSelf = self;
// mbgl::Scheduler::GetCurrent() scheduler means "run callback on current (ie UI/main) thread"
Expand All @@ -177,8 +175,6 @@ - (void)startWithQueue:(dispatch_queue_t)queue completionHandler:(MGLMapSnapshot
// If self had died, _snapshotCallback would have been destroyed and this block would not be executed
NSCAssert(strongSelf, @"Snapshot callback executed after being destroyed.");

strongSelf.loading = false;

if (!strongSelf.completion)
return;

Expand Down Expand Up @@ -504,8 +500,10 @@ + (CGSize)attributionTextSizeWithStyle:(MGLAttributionInfoStyle)attributionStyle

- (void)cancel
{
self.cancelled = YES;

if (_snapshotCallback) {
[MGLMapSnapshotter completeWithErrorCode:MGLErrorCodeSnapshotUserCancelled
[MGLMapSnapshotter completeWithErrorCode:MGLErrorCodeSnapshotFailed
description:[NSString stringWithFormat:@"MGLMapSnapshotter cancelled from %s", __PRETTY_FUNCTION__]
onQueue:self.resultQueue
completion:self.completion];
Expand Down
4 changes: 1 addition & 3 deletions platform/darwin/src/MGLTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ typedef NS_ENUM(NSInteger, MGLErrorCode) {
/** An attempt to load the style failed. */
MGLErrorCodeLoadStyleFailed = 5,
/** An error occurred while snapshotting the map. */
MGLErrorCodeSnapshotFailed = 6,
/** The user cancelled a map snapshot. */
MGLErrorCodeSnapshotUserCancelled = 7,
MGLErrorCodeSnapshotFailed = 6
};

/** Options for enabling debugging features in an `MGLMapView` instance. */
Expand Down
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Added `MGLShapeOfflineRegion` for defining arbitrarily shaped offline regions [#11447](https://github.com/mapbox/mapbox-gl-native/pull/11447)
* Added a one-time warning about possible attribute loss when initializing an `MGLShapeSource` with an `MGLShapeCollection` [#12625](https://github.com/mapbox/mapbox-gl-native/pull/12625)
* Added an `-[MGLMapViewDelegate mapView:shapeAnnotationIsEnabled:]` method to specify whether an annotation is selectable. ([#12352](https://github.com/mapbox/mapbox-gl-native/pull/12352))
* Fixed bug where completion block passed to `-[MGLMapSnapshotter startWithQueue:completionHandler:]` was not being called in all code paths. ([#12355](https://github.com/mapbox/mapbox-gl-native/pull/12355))

### Offline
* Improved SQLite error handling for offline databases that return specific errors. [#12224](https://github.com/mapbox/mapbox-gl-native/pull/12224)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#import "MGLMapViewIntegrationTest.h"

@interface MGLMapSnapshotter ()
@property (nonatomic) BOOL cancelled;
@end


@interface MGLMapSnapshotterTest : MGLMapViewIntegrationTest
@end

Expand Down Expand Up @@ -79,7 +84,8 @@ - (void)testDeallocatingSnapshotterDuringSnapshot {

dispatch_async(dispatch_get_main_queue(), ^{
MGLMapSnapshotter *snapshotter = snapshotterWithCoordinates(coord, size);

__weak MGLMapSnapshotter *weakSnapshotter = snapshotter;

[snapshotter startWithCompletionHandler:^(MGLMapSnapshot * _Nullable snapshot, NSError * _Nullable error) {
// We expect this completion block to be called with an error
__typeof__(self) strongself = weakself;
Expand All @@ -88,6 +94,8 @@ - (void)testDeallocatingSnapshotterDuringSnapshot {
MGLTestAssert(strongself,
([error.domain isEqualToString:MGLErrorDomain] && error.code == MGLErrorCodeSnapshotFailed),
@"Should have errored");
MGLTestAssertNil(strongself, weakSnapshotter, @"Snapshotter should have been deallocated");

dispatch_group_leave(dg);
}];
});
Expand Down Expand Up @@ -170,8 +178,9 @@ - (void)testCancellingSnapshot {

MGLTestAssertNil(strongself, snapshot);
MGLTestAssert(strongself,
([error.domain isEqualToString:MGLErrorDomain] && error.code == MGLErrorCodeSnapshotUserCancelled),
([error.domain isEqualToString:MGLErrorDomain] && error.code == MGLErrorCodeSnapshotFailed),
@"Should have been cancelled");
MGLTestAssert(strongself, snapshotter.cancelled, @"Should have been cancelled");
[expectation fulfill];
}];

Expand Down
2 changes: 1 addition & 1 deletion platform/ios/ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@
927FBCFA1F4DAA8300F8BF1F /* MBXSnapshotsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBXSnapshotsViewController.h; sourceTree = "<group>"; };
927FBCFB1F4DAA8300F8BF1F /* MBXSnapshotsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBXSnapshotsViewController.m; sourceTree = "<group>"; };
927FBCFD1F4DB05500F8BF1F /* MGLMapSnapshotter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLMapSnapshotter.h; sourceTree = "<group>"; };
927FBCFE1F4DB05500F8BF1F /* MGLMapSnapshotter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLMapSnapshotter.mm; sourceTree = "<group>"; };
927FBCFE1F4DB05500F8BF1F /* MGLMapSnapshotter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLMapSnapshotter.mm; sourceTree = "<group>"; wrapsLines = 0; };
92F2C3EC1F0E3C3A00268EC0 /* MGLRendererFrontend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLRendererFrontend.h; sourceTree = "<group>"; };
92FC0AE7207CEE16007B6B54 /* MGLShapeOfflineRegion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLShapeOfflineRegion.h; sourceTree = "<group>"; };
92FC0AE8207CEE16007B6B54 /* MGLShapeOfflineRegion_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLShapeOfflineRegion_Private.h; sourceTree = "<group>"; };
Expand Down
4 changes: 2 additions & 2 deletions platform/macos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Fixed inconsistencies in exception naming. ([#12583](https://github.com/mapbox/mapbox-gl-native/issues/12583))
* Added `MGLShapeOfflineRegion` for defining arbitrarily shaped offline regions [#11447](https://github.com/mapbox/mapbox-gl-native/pull/11447)
* Added an `-[MGLMapViewDelegate mapView:shapeAnnotationIsEnabled:]` method to specify whether an annotation is selectable. ([#12352](https://github.com/mapbox/mapbox-gl-native/pull/12352))
* Fixed bug where completion block passed to `-[MGLMapSnapshotter startWithQueue:completionHandler:]` was not being called in all code paths. ([#12355](https://github.com/mapbox/mapbox-gl-native/pull/12355))


# 0.10.0 - August 15, 2018

Expand Down Expand Up @@ -42,8 +44,6 @@
* Fixed an issue where `-[MGLMapShapshot pointForCoordinate:]` returned incorrect points. ([#12221](https://github.com/mapbox/mapbox-gl-native/pull/12221))
* Improved caching performance. ([#12072](https://github.com/mapbox/mapbox-gl-native/pull/12072))
* Remove unnecessary memory use when collision debug mode is disabled. ([#12294](https://github.com/mapbox/mapbox-gl-native/issues/12294))
* Changed `-[MGLMapSnapshotter cancel]` to call the completion block (originally passed to `-[MGLMapSnapshotter startWithQueue:completionHandler:]`) with an `NSError` (error code `MGLErrorCodeSnapshotUserCancelled`) if the snapshot has not finished. ([#12355](https://github.com/mapbox/mapbox-gl-native/pull/12355))


## 0.8.0 - June 20, 2018

Expand Down

0 comments on commit 323d4cb

Please sign in to comment.