谷歌地图与Collection< __ NSArrayM:0x17d280e0>崩溃在被列举时被突变

时间:2016-08-25 12:20:34

标签: ios objective-c google-maps-sdk-ios

Google Maps SDK版本:2.0.1

iOS版本:9.3.x,9.2.x 7.0.x

启用ARC。

崩溃堆栈: 集合< __ NSArrayM:0x17d280e0>在被枚举时被突变

0  CoreFoundation                 0x2501c10b __exceptionPreprocess
1  libobjc.A.dylib                0x247c2e17 objc_exception_throw
2  CoreFoundation                 0x2501bb91 -[NSException name]
3  MyApp                          0x18e1b5 -[GMSVectorMapView buildVisibleAccessibilityItems]
4  MyApp                          0x2a2d13 -[GMSMapView updateOverlay:]ssfsdf
5  MyApp                          0x2dc04f -[GMSOverlay setMap:]
6  MyApp                          0xce87b __25-[VCMain updateMarkersOnMap]_block_invoke (VCMain.m:1186)
7  libdispatch.dylib              0x24b95b5b _dispatch_call_block_and_release
8  libdispatch.dylib              0x24ba4921 _dispatch_root_queue_drain
9  libdispatch.dylib              0x24ba4305 _dispatch_worker_thread3
10 libsystem_pthread.dylib        0x24d53b29 (Missing)
11 libsystem_pthread.dylib        0x24d53718 (Missing)

执行以下代码时会发生此崩溃:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0 {
    NSArray *coordinates = [networkClient getCoordinates];
    for (NSDictionary *coord in coordinates) {

        double double_lat = [[coord objectForKey:@"geoy"] doubleValue];
        double double_long = [[coord objectForKey:@"geox"] doubleValue];

        CLLocationCoordinate2D location = CLLocationCoordinate2DMake(double_lat, double_long);

        GMSMarker *marker = [GMSMarker markerWithPosition:location];
        marker.icon = [UIImage imageNamed: @"image"];
        marker.title = title;
        marker.snippet = subtitle;
        marker.groundAnchor = CGPointMake(0.5, 0.5);

        marker.map = mapMainGoogle; // crash
    }

}

我的应用程序也会执行以下代码:

[mapMainGoogle clear];

我尝试在@synchronized(mapMainGoogle)或NSLock锁定/解锁中放置[GMSMarker setMap]和[GMSMapView clear]方法。但它没有帮助,崩溃仍然出现。

当我将这些方法放在dispatch_async(dispatch_get_main_qeueue())块中时,它随机崩溃并发生以下崩溃:

崩溃堆栈: EXC_BAD_ACCESS KERN_INVALID_ADDRESS

0  libobjc.A.dylib                0x22a43a86 objc_msgSend + 5
1  MyApp                          0x18f6d7 -[NSThread(GTMBlocksAdditions) GMSx_gtm_performBlock:] + 1435351
2  MyApp                          0x2a3025 -[GMSMarker displayLayer:] + 360140
3  QuartzCore                     0x258dca83 CA::Layer::display() + 106
4  MyApp                          0x2dbda5 -[GMSMarkerLayer display] + 592972
5  QuartzCore                     0x258c0f0d CA::Layer::display_if_needed(CA::Transaction*) + 208
6  QuartzCore                     0x258c0bc5 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
7  QuartzCore                     0x258c0081 CA::Context::commit_transaction(CA::Transaction*) + 368
8  QuartzCore                     0x258bfd55 CA::Transaction::commit() + 520
9  QuartzCore                     0x258eda73 CA::Transaction::release_thread(void*) + 310
10 libsystem_pthread.dylib        0x22fab905 _pthread_tsd_cleanup + 508
11 libsystem_pthread.dylib        0x22fab507 _pthread_exit + 86
12 libsystem_pthread.dylib        0x22faae21 _pthread_wqthread + 1044
13 libsystem_pthread.dylib        0x22faa9fc start_wqthread + 8

请提出任何建议。

1 个答案:

答案 0 :(得分:0)

错误消息告诉您究竟出了什么问题:在枚举数组时会修改数组。例如,通过使用不可变数组来改进这一点。 “@synchronized”无法帮助,因为您在后台线程中进行迭代,后者不知道@synchronized。