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

[ios] Crash fix on render with view-backed annotations #8513

Conversation

fabian-guerra
Copy link
Contributor

Fixes #8163 while this is only a nil check, we need to continue investigating why annotationContext.annotation is nil when calling visibleAnnotationsInRect

@fabian-guerra fabian-guerra added crash iOS Mapbox Maps SDK for iOS labels Mar 23, 2017
@fabian-guerra fabian-guerra added this to the ios-v3.5.1 milestone Mar 23, 2017
@fabian-guerra fabian-guerra self-assigned this Mar 23, 2017
@mention-bot
Copy link

@fabian-guerra, thanks for your PR! By analyzing this pull request, we identified @1ec5, @incanus and @boundsj to be potential reviewers.

@1ec5
Copy link
Contributor

1ec5 commented Mar 23, 2017

We should audit the MGLMapView implementation for places where we use subscript notation ([]) on _annotationContextsByAnnotationTag. The tricky thing about std::map is that subscripting with a nonexistent key will create a bogus value to go with the key. That could be how the context ends up with a nil annotation. In most places, we’re using std::map::at(), which throws an exception, and checking for existence (with count()) before calling at().

@fabian-guerra
Copy link
Contributor Author

@1ec5 even before I added a nil check we did checked with count()

            if (!_annotationContextsByAnnotationTag.count(annotationTag))
            {
                continue;
            }
            MGLAnnotationContext annotationContext = _annotationContextsByAnnotationTag.at(annotationTag);
            if (annotationContext.annotation)
            {
                [annotations addObject:annotationContext.annotation];
            }

@fabian-guerra fabian-guerra reopened this Mar 28, 2017
@fabian-guerra fabian-guerra merged commit c5c6910 into release-ios-v3.5.0-android-v5.0.0 Mar 28, 2017
@fabian-guerra fabian-guerra deleted the fabian-fix-visible-annotations-in-rect branch March 28, 2017 20:06
@1ec5
Copy link
Contributor

1ec5 commented Mar 29, 2017

even before I added a nil check we did checked with count()

Yes, but there are several other places in the code that use subscripting notation on _annotationContextsByAnnotationTag – could one of these places be responsible for the nil annotation? This PR is fine as a stopgap fix, but unless we also hunt down the root cause, we may well end up with bizarre behavior elsewhere in the annotation code and have even less of an idea what’s causing it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
crash iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants