This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
[ios] Work around annotation race condition - #6924
Merged
Merged
Conversation
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, 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
suggested changes
Nov 4, 2016
1ec5
left a comment
Contributor
There was a problem hiding this comment.
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)) |
Contributor
There was a problem hiding this comment.
Can you make these changes in the macOS implementation too?
Analogue to the iOS commit for same
1ec5
suggested changes
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]) |
Contributor
There was a problem hiding this comment.
Also make this change in the macOS implementation.
1ec5
approved these changes
Nov 4, 2016
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
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