2012-09-11 5 views
2

나는 일반적으로 매우 잘 작동 다음과 같은 방법으로 NSFileWrapper 데이터를 보관 해제 :NSKeyedUnarchiver SIGBUS BUS_ADRALN는 충돌

- (id)decodeObjectFromWrapperWithPreferredFilename:(NSString *)p { 

    NSFileWrapper *wrapper = [self.fileWrapper.fileWrappers objectForKey:p]; 
    if (!wrapper) { 
     NSLog(@"Unexpected error: Couldn't find %@ in file wrapper!", p); 
     return nil; 
    } 

    NSData *data = [wrapper regularFileContents]; 
    NSKeyedUnarchiver *unarchiver; 
    @try { 
     unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; 
    } 
    @catch (NSException *exception) { 
     NSLog(@"exception: %@", exception); 
     [TestFlight passCheckpoint:@"FILE LOADING EXCEPTION!"]; 
     UIAlertView *alertOFF = [[UIAlertView alloc] 
           initWithTitle:@"Corrupt" 
           message:@"There was an error loading a file! Please contact [email protected]" 
           delegate:self 
           cancelButtonTitle:@"OK" 
           otherButtonTitles:nil]; 
     [alertOFF show]; 

    } 
    return [unarchiver decodeObjectForKey:@"data"]; 
} 

그러나, 나는 때때로 라인 unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];에 대한 SIGBUS 충돌을 얻을. 예외 의이 유형은 내 예외 처리기에 잡히지 않는 것 같아요? 그러한 예외를 어떻게 처리 할 수 ​​있습니까?

Exception Type:SIGBUSCode:BUS_ADRALN 
Thread 0 Crashed 
Latest Crash: 11 September 2012 at 06:23 
0 Foundation 
-[NSKeyedUnarchiver initForReadingWithData:] + 389 
1 Meernotes ✭  FRNBDocument.m line 221 
-[FRNBDocument decodeObjectFromWrapperWithPreferredFilename:] + 221 
2 Meernotes FRNBDocument.m line 155 
-[FRNBDocument settings] + 155 
3 Meernotes ModelController.m line 497 
__39-[ModelController previewLoadDocAtURL:]_block_invoke_0 + 497 
4 
... 
libdispatch.dylib 
_dispatch_barrier_sync_f_slow_invoke + 78 
5 libdispatch.dylib 
_dispatch_main_queue_callback_4CF$VARIANT$up + 196 
6 CoreFoundation 
__CFRunLoopRun + 1268 
7 CoreFoundation 
CFRunLoopRunSpecific + 300 
8 CoreFoundation 
CFRunLoopRunInMode + 104 
9 GraphicsServices 
GSEventRunModal + 136 
10 UIKit 
UIApplicationMain + 1080 
11 Meernotes main.m line 16 
main + 16 

답변

1

첫째, 당신이 전체 충돌 보고서의 확신 : 여기

는 Crashlytics 충돌 보고서입니다? 좀 더 자세한 내용이 있어야합니다 ...

어쨌든, 그것은 예외는 아닙니다. 그것은 신호이며 일반적으로 메모리 액세스 오류를 의미합니다. SIGBUS를 받았다면 기본적으로 메모리 오류 (보통 잘못된 포인터에 액세스하는 코드)를 의미합니다.

가장 많이 발생하는 원인은 [wrapper regularFileContents]에서받은 데이터 개체가 어떻게 든 손상되었다는 것입니다. 대부분의 경우, 그것은 nil을 리턴합니다.

regularFileContents에 대한 문서 :

Discussion

This method may return nil if the user modifies the file after you call readFromURL:options:error: or initWithURL:options:error: but before NSFileWrapper has read the contents of the file. Use the NSFileWrapperReadingImmediate reading option to reduce the likelihood of that problem.

내가 시작 했죠 곳이 될 것입니다. 파일 데이터가 손상되어 unarchiver가 잘못된 데이터를 질식시킬 수도 있습니다.

기본적으로이 예외를 무시하고 무시할 수 있습니다. 프로그램에서 수정해야하는 버그를 나타냅니다.

+2

또한 'return [unarchiver decodeObjectForKey : @ "data"];'를 변경해야합니다. 이 객체를 임시로 저장하려면 클래스 문서별로 unfiniver에게 "finishDecoding '메시지를 보낸 다음 임시를 반환하십시오. –

+0

@DavidH 좋은 지적. –