diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-08-05 14:32:37 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-08-05 16:15:45 +0200 |
commit | c523391b2024bfa6ab5d60c8a86fe3bf735c588f (patch) | |
tree | 5d2ac9f31d721bfb545a179ffc239d7d9a3e6e8b /platform/darwin | |
parent | c763c262c87a4ae76489e856cc58392c853372a1 (diff) | |
download | qtlocation-mapboxgl-c523391b2024bfa6ab5d60c8a86fe3bf735c588f.tar.gz |
[macos,ios] Fix rare crash when downloading tiles that returned a 404
We were capturing the reference to an object that could go away when the request was canceled. However, the lambda could still be invoked by NSURLSession, creating a race condition with a resulting crash when the response to a tile request was 404 Not Found.
Diffstat (limited to 'platform/darwin')
-rw-r--r-- | platform/darwin/src/http_file_source.mm | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm index 79810546b3..5737d8b999 100644 --- a/platform/darwin/src/http_file_source.mm +++ b/platform/darwin/src/http_file_source.mm @@ -245,8 +245,10 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource, } [req addValue:impl->userAgent forHTTPHeaderField:@"User-Agent"]; - - if (resource.kind == mbgl::Resource::Kind::Tile) { + + const bool isTile = resource.kind == mbgl::Resource::Kind::Tile; + + if (isTile) { [[MGLNetworkConfiguration sharedManager] startDownloadEvent:url.relativePath type:@"tile"]; } @@ -322,7 +324,7 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource, if (responseCode == 200) { response.data = std::make_shared<std::string>((const char *)[data bytes], [data length]); - } else if (responseCode == 204 || (responseCode == 404 && resource.kind == Resource::Kind::Tile)) { + } else if (responseCode == 204 || (responseCode == 404 && isTile)) { response.noContent = true; } else if (responseCode == 304) { response.notModified = true; |