2013-09-30 30 views
1

我的堆棧跟蹤有關的地圖被枚舉..NSGenericException「原因:」 ***集合<__ NSArrayM:0x12a9f7d0>突變而MAPS

NSGenericException發生,如果我們試圖修改數組,正在枚舉...我已經採取了關心不修改枚舉數組。

for (int k=0;k<[[af factsArray] count];k++) 
     //here af is my object 
    { 
    Facts *f = [[af factsArray] objectAtIndex:k]; 

    //here i'm removing unecessary characters from my point String 

    NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"POINT()"]; 

    NSString *pointsStr = [[[f.factPosition mutableCopy] componentsSeparatedByCharactersInSet:doNotWant] componentsJoinedByString:@""]; 

    NSArray *pieces = [[pointsStr componentsSeparatedByString:@" "] copy]; 
    CGPoint point = CGPointMake([[pieces objectAtIndex:2] floatValue], [[pieces objectAtIndex:1] floatValue]); 
    NSValue *val = [NSValue valueWithCGPoint:point]; 

    [routePointsArray addObject:val]; 

} 

NSInteger pointsCount = routePointsArray.count; 

CLLocationCoordinate2D pointsToUse[pointsCount]; 

for(int i = 0; i < pointsCount; i++) 
{ 
    CGPoint p = [[routePointsArray objectAtIndex:i] CGPointValue]; 
    pointsToUse[i] = CLLocationCoordinate2DMake(p.x,p.y); 
} 

MKPolyline *myPolyline = [MKPolyline polylineWithCoordinates:pointsToUse  count:pointsCount]; 
[routeOverlays addObject:myPolyline]; 

NSLog(@"routeOverlays count:%d",[routeOverlays count]); 


//adding overlays 

dispatch_async(dispatch_get_main_queue(), ^{ 
    [self.map addOverlays:routeOverlays]; 
}); 

誰能告訴我這個問題的代碼,因爲它有時會崩潰,有時沒有。 這裏是我的堆棧跟蹤

*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x12a9f7d0> was mutated while being enumerated.' 
     *** First throw call stack: 
     (
      0 CoreFoundation      0x01a2f5e4 __exceptionPreprocess + 180 
      1 libobjc.A.dylib      0x017b28b6 objc_exception_throw + 44 
      2 CoreFoundation      0x01abf3b5 __NSFastEnumerationMutationHandler + 165 
      3 VectorKit       0x04029d7e -[VKMapModel layoutScene:withContext:] + 3854 
      4 VectorKit       0x0401fc8e -[VKModelObject layoutSceneIfNeeded:withContext:] + 110 
      5 VectorKit       0x04028bff -[VKMapModel layoutSceneIfNeeded:withContext:] + 143 
      6 VectorKit       0x0401fd35 -[VKModelObject layoutSceneIfNeeded:withContext:] + 277 
      7 VectorKit       0x0403f278 -[VKWorld layoutScene:withContext:] + 56 
      8 VectorKit       0x0402eac6 -[VKScreenCanvas drawWithTimestamp:] + 358 
      9 VectorKit       0x04019c15 -[VKMapCanvas drawWithTimestamp:] + 149 
      10 VectorKit       0x0402e4ee -[VKScreenCanvas onTimerFired:] + 142 
      11 libobjc.A.dylib      0x017c481f -[NSObject performSelector:withObject:] + 70 
      12 VectorKit       0x041adbdc -[VGLDisplayLink _displayLinkFired:] + 60 
      13 QuartzCore       0x045f3fca _ZN2CA7Display15DisplayLinkItem8dispatchEv + 48 
      14 QuartzCore       0x045f3e86 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 310 
      15 QuartzCore       0x045f43ab _ZN2CA7Display16TimerDisplayLink8callbackEP16__CFRunLoopTimerPv + 123 
      16 CoreFoundation      0x019edc46 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22 
      17 CoreFoundation      0x019ed62d __CFRunLoopDoTimer + 1181 
      18 CoreFoundation      0x019d5698 __CFRunLoopRun + 1816 
      19 CoreFoundation      0x019d4b33 CFRunLoopRunSpecific + 467 
      20 CoreFoundation      0x019d494b CFRunLoopRunInMode + 123 
      21 GraphicsServices     0x02c469d7 GSEventRunModal + 192 
      22 GraphicsServices     0x02c467fe GSEventRun + 104 
      23 UIKit        0x0031894b UIApplicationMain + 1225 
      24 SnapTraq       0x0002029d main + 141 
      25 libdyld.dylib      0x022c1725 start + 0 
     ) 
     libc++abi.dylib: terminating with uncaught exception of type NSException 
+1

你檢查了什麼行引發異常通過爲每個引發的異常添加一個斷點嗎? – micantox

回答

1

我要感謝@micantox他試圖解決我的問題......

不管怎麼說,我已經解決了我自己的問題。

我試圖從不同的線程執行循環..導致實際問題。

單線程是使用NSArray添加註釋,其他線程正在刪除那些NSArray對象。爲了避免這個問題我已經使用

@synchronized(self) 
    { 
     // your code goes here 
    } 
相關問題