-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Harden std::map usage in MGLMapVIew #8637
Harden std::map usage in MGLMapVIew #8637
Conversation
Replaced std::map::operator[] usage with std::map::at(). Backed up an assertion on iOS with a guard when -annotationTagsInRect: returns the tag of a nonexistent annotation, for consistency with macOS. Removed an unnecessary and risky subscript into _annotationContextsByAnnotationTag in -positioningRectForCalloutForAnnotationWithTag: on iOS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
@@ -3550,8 +3550,12 @@ - (MGLAnnotationTag)annotationTagAtPoint:(CGPoint)point persistingResults:(BOOL) | |||
{ | |||
id <MGLAnnotation> annotation = [self annotationWithTag:annotationTag]; | |||
NSAssert(annotation, @"Unknown annotation found nearby tap"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that this assertion will fail in a debug build if you perform the reproduction steps in #8163 (comment). The issue is that mbgl notion of visible annotations will always lag a bit behind the platforms' notion of the same when annotations are removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider that a bug, or is it an edge case we want to fail gracefully around from now on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a bug that is an edge case 😄
But, the fix would require a callback feature for at least some of the mbgl APIs right? The platforms should not actually update their state until after core has completed updating its state (i.e. removing annotations so that queries of visible annotations won't include them)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, and we should make sure the map remains usable even in debug builds. That could be tail work, though; it seems like #8513 would have the same considerations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Replaced
std::map::operator[]
usage withstd::map::at()
. Backed up an assertion on iOS with a guard when-annotationTagsInRect:
returns the tag of a nonexistent annotation, for consistency with macOS. Removed an unnecessary and risky subscript into_annotationContextsByAnnotationTag
in-positioningRectForCalloutForAnnotationWithTag:
on iOS./ref #8163 (comment)