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 
    }