Outdooractive / route-me

Open source map library for iOS
Other
122 stars 400 forks source link

visibleAnnotations Array Of RMMapView is mutated while beeing enumerated #126

Open jklimke opened 11 years ago

jklimke commented 11 years ago

I found a synchronization problem within the addAnnotations method of RMMapView. I am currently doing under some circumstances a parallel load of data for Annotations from the web. When i add them (not necessarily in the same thread), via the method addAnnotations, it happens that there is a parallel modification of RMMapViews _visibleAnnotations property within the method correctPositionOfAllAnnotationsIncludingInvisibles

As a fix i would propose to include the method call into the synchronization, or aquiring a second lock on visibleAnnotations during the method correctPositionOfAllAnnotationsIncludingInvisibles. Currently only the _annotations array is synchronized.

 @synchronized (_annotations)
    {
        [_annotations addObjectsFromArray:newAnnotations];
        [self.quadTree addAnnotations:newAnnotations];
    }

    [self correctPositionOfAllAnnotationsIncludingInvisibles:YES animated:NO];

The same should apply to the removeAnnotations method.

trasch commented 11 years ago

Thanks for the catch, I will have a look at it!