This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
Keep MGLMapSnapshotter alive through completion #211
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Strongly capture MGLMapSnapshotter until its completion handler finishes executing. The developer no longer needs to explicitly capture the snapshotter in the completion handler to prevent it from being canceled or deallocated, because the internal completion handler does so for the developer.
Before #210, a snapshotter that wasn’t captured in its completion handler would be deallocated as soon as it went out of scope, but the completion handler would be called with an error “headlessly” after the snapshotter got deallocated. As of #210, the same snapshotter would’ve silently gone away without calling the completion handler, since it was considered the responsibility of the developer to hang onto the snapshotter. As of this PR, the developer is no longer required to hang onto the snapshotter, and the completion handler will generally receive a snapshot rather than an error.
This new behavior matches MapKit’s MKMapSnapshotter and is ideal for one-off usage. I had shied away from it in #200 (comment) because of the complexity around keeping the completion handler alive, but #210 gives us more confidence about the control flow and lifetime of any captured state. Nonetheless, this PR needs extra scrutiny because it possibly reintroduces edge cases that #210 had eliminated by reducing the snapshotter’s scope. In particular, we should make sure the application can reliably terminate while snapshotters are active without crashing.
Depends on #210. Fixes mapbox/mapbox-gl-native#12336 in a different way.
/cc @mapbox/maps-ios @alexshalamov