[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 8e200ae387
commit 0bd9eac174
2 changed files with 10 additions and 3 deletions

View File

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

View File

@@ -2,6 +2,10 @@
Mapbox welcomes participation and contributions from everyone. Please read [CONTRIBUTING.md](../../CONTRIBUTING.md) to get started.
## 3.7.7
* Fixed a crash when removing an `MGLOfflinePack`. ([#6092](https://github.com/mapbox/mapbox-gl-native/issues/6092))
## 3.7.6 - March 12, 2018
* Fixed an issue where full-resolution tiles could fail to replace lower-resolution placeholders. ([#11227](https://github.com/mapbox/mapbox-gl-native/pull/11227))