[ios, macos] Avoid implicit capture of MBGLOfflineRegionObserver this pointer

MBGLOfflineRegionObserver is owned by the offline database thread, and might be destroyed by the time the dispatch_async completes. Instead of implicitly capturing this, capture a copy of the MBGLOfflinePack weak pointer.
This commit is contained in:
John Firebaugh
2018-05-02 12:34:50 -07:00
parent 7125ad9955
commit 1c22374eac

View File

@@ -227,19 +227,22 @@ NSError *MGLErrorFromResponseError(mbgl::Response::Error error) {
@end
void MBGLOfflineRegionObserver::statusChanged(mbgl::OfflineRegionStatus status) {
__weak MBGLOfflinePack *_pack = pack;
dispatch_async(dispatch_get_main_queue(), ^{
[pack offlineRegionStatusDidChange:status];
[_pack offlineRegionStatusDidChange:status];
});
}
void MBGLOfflineRegionObserver::responseError(mbgl::Response::Error error) {
__weak MBGLOfflinePack *_pack = pack;
dispatch_async(dispatch_get_main_queue(), ^{
[pack didReceiveError:MGLErrorFromResponseError(error)];
[_pack didReceiveError:MGLErrorFromResponseError(error)];
});
}
void MBGLOfflineRegionObserver::mapboxTileCountLimitExceeded(uint64_t limit) {
__weak MBGLOfflinePack *_pack = pack;
dispatch_async(dispatch_get_main_queue(), ^{
[pack didReceiveMaximumAllowedMapboxTiles:limit];
[_pack didReceiveMaximumAllowedMapboxTiles:limit];
});
}