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

[ios] Work around annotation race condition - #6924

Merged
boundsj merged 3 commits into
release-ios-v3.4.0from
boundsj-tidy-up-annotation-handling
Nov 4, 2016
Merged

boundsj merged 3 commits into
release-ios-v3.4.0from
boundsj-tidy-up-annotation-handling

Conversation

@boundsj

@boundsj boundsj commented Nov 4, 2016

Copy link
Copy Markdown
Contributor

Fixes #6901

When annotations are removed concurrently with being updated because of a map redraw, it is possible that mbgl will still consider an annotation to exist depending on what part of the map lifecycle the call update annotations happens. However, the annotation context by
tag map in MGLMapView (on the main thread) will always be up to date.
This adds a guard that uses that map to avoid considering annotations that have actually been removed as visible.

Another issue was that adding the same annotation object twice has always been allowed and has worked, visually. However, a recent refactor to make the reuse queue work correctly is not tolerant of the a single view representing two annotation instances that are the same.
The effect is that a new UIView will be generated for each (clone) annotation that is added and only the last view will move with the map. The other views become detached and float around in the view as the map is panned. This commit adds a guard to make adding an annotation instance a no-op if it has already been added before.

cc @1ec5 @incanus @bsudekum

When annotations are removed concurrently with being updated because
of a map redraw, it is possible that mbgl will still consider an
annotation to exist depending on what part of the map lifecycle the
call update annotations happens. However, the annotation context by
tag map in MGLMapView (on the main thread) will always be up to date.
This adds a guard that uses that map to avoid considering annotations
that have actually been removed as visible.

Another issue was that adding the same annotation object twice has
always been allowed and has worked, visually. However, a recent
refactor to make the reuse queue work correctly is not tolerant of the
a single view representing two annotation instances that are the same.
The effect is that a new UIView will be generated for each (clone)
annotation that is added and only the last view will move with the map.
The other views become detached and float around in the view as the
map is panned. This commit adds a guard to make adding an annotation
instance a no-op if it has already been added before.
@boundsj boundsj added refactor crash ✓ ready for review annotations Annotations on iOS and macOS or markers on Android release blocker Blocks the next final release labels Nov 4, 2016
@boundsj boundsj added this to the ios-v3.4.0 milestone Nov 4, 2016
@boundsj boundsj self-assigned this Nov 4, 2016
@mention-bot

Copy link
Copy Markdown

@boundsj, thanks for your PR! By analyzing the history of the files in this pull request, we identified @1ec5, @incanus and @friedbunny to be potential reviewers.

@1ec5 1ec5 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.

This commit adds a guard to make adding an annotation instance a no-op if it has already been added before.

Perfect – that’s exactly what should happen.

for (auto const& annotationTag: annotationTags)
{
MGLAnnotationContext annotationContext = _annotationContextsByAnnotationTag[annotationTag];
if (!_annotationContextsByAnnotationTag.count(annotationTag))

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.

Can you make these changes in the macOS implementation too?

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.

Oops. Done in 02e5978

Analogue to the iOS commit for same
@boundsj boundsj added macOS Mapbox Maps SDK for macOS iOS Mapbox Maps SDK for iOS labels Nov 4, 2016
NSAssert([annotation conformsToProtocol:@protocol(MGLAnnotation)], @"annotation should conform to MGLAnnotation");

// adding the same annotation object twice is a no-op
if ([self.annotations containsObject:annotation])

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.

Also make this change in the macOS implementation.

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.

😬 done in ecf14e3

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

annotations Annotations on iOS and macOS or markers on Android crash iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS refactor release blocker Blocks the next final release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants