Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Keep MGLMapSnapshotter alive through completion - #211

Merged
1ec5 merged 2 commits into
masterfrom
1ec5-snapshotter-keep-alive-12336
Mar 17, 2020
Merged

1ec5 merged 2 commits into
masterfrom
1ec5-snapshotter-keep-alive-12336

Conversation

@1ec5

@1ec5 1ec5 commented Mar 14, 2020 •

Copy link
Copy Markdown
Contributor

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

Comment thread platform/ios/CHANGELOG.md Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should link to this PR instead of #210.

@1ec5 1ec5 Mar 14, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is inaccurate: it crept back in when I reverted #210’s changes to the test, but we want the completion handler to be called with a valid snapshot now.

@1ec5
1ec5 force-pushed the 1ec5-snapshotter-keep-alive-12336 branch from 272fdfe to 944388e Compare March 16, 2020 18:31

@julianrex julianrex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in favour of landing this PR with #210 - I feel it's solves a lot of issues.

Just a question about one of the tests - is this a comment/function name issue or just a typo?

@1ec5
1ec5 force-pushed the 1ec5-snapshotter-parallel-state-209 branch from 055a482 to d357f8c Compare March 17, 2020 01:15
@1ec5
1ec5 force-pushed the 1ec5-snapshotter-keep-alive-12336 branch from 54f4f6d to 363610c Compare March 17, 2020 01:17
@1ec5
1ec5 changed the base branch from 1ec5-snapshotter-parallel-state-209 to master March 17, 2020 02:38
@1ec5
1ec5 merged commit 363610c into master Mar 17, 2020
@1ec5
1ec5 deleted the 1ec5-snapshotter-keep-alive-12336 branch March 17, 2020 02:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request ios macOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants