간단한 텍스트 편집기 (사용자 정의가 거의없는 Lion의 새 문서 기반 앱 템플리트 사용)에 대한 NSDocument 하위 클래스가 있으며 파일 내용을 텍스트 저장소로로드하는 이상한 버그가 발생합니다. NSTextStorage에서 혼란스러운 인코딩 예외가 발생했습니다.
- 이 (디버그 빌드로) 엑스 코드에서 응용 프로그램을 실행 : 나는 경우
- (void)loadTextContentIntoStorage { if (!self.textStorage || !textContentToLoad) return; ... [self.textStorage beginEditing]; // NSLog(@"storage: %@ length: %lu textContent: %@", self.textStorage, (unsigned long)self.textStorage.length, textContentToLoad); // [self.textStorage replaceCharactersInRange:NSMakeRange(0, self.textStorage.length) withString:textContentToLoad]; [self.textStorage replaceCharactersInRange:NSMakeRange(0, 0) withString:@"hello world"]; .. [self.textStorage endEditing]; }
버그가 발생 : 여기
내 코드입니다 (문서를 닫지 않고) - Xcode에서 앱을 다시 실행하십시오.
-replaceCharactersInRange:withString:
에서 "문자열 0x10004d430의 바이트를 _NSCStringEncoding으로 변환 할 수 없습니다"라는 오류가 발생합니다.
는하지만 그것은 단지 응용 프로그램의 모든 초 발사에서 발생 (세 번째 발사가 중단되지 않으며, 그것은 는 자동으로 이전의 시간을 열려고 추락 문서를 다시 열 것). 또한 Xcode에서 앱을 실행할 때만 발생합니다. 릴리스 빌드는 실행시 충돌하지 않습니다.
자동 저장 시스템에서 인코딩 문제 일 수 있다고 생각했지만 코드를 주석 처리하고 텍스트 뷰에 @ "hello world"문자열을로드 할 때 충돌이 발생합니다 (위의 코드 참조) . 비슷하게, 주석 처리 된 NSLog()
은 이상한 것을 보여주지 않습니다. 텍스트 저장소는 유효하며 (xib 파일에서로드 됨) 텍스트 저장 길이는 0이고 textContent는 열려있는 파일의 내용입니다.
--- 편집 ---
나는이 문제는 com.apple.security.app-sandbox
자격에 어떤 식 으로든 관련이있다 배웠다. 인 타이틀먼트/샌드 박스가 인 경우 인 경우 내 은이 아닙니다. 자격 또는 app-sandbox 기능 중 하나가 이 비활성화 된 경우 인 경우 이전에 연 문서를 복원하려고 시도 할 때마다 내 앱이 충돌합니다.
xcode에서 빌드/실행을 할 때 충돌이 발생했는데, 이는 샌드 박스가 비활성화 된 유일한 빌드 구성 이었기 때문입니다. ---/EDIT
---이
가사람이 어떤 아이디어가 있습니까? 전체 예외는 다음과 전체 소스 코드는 GitHub의에 : https://github.com/abhibeckert/Dux/blob/master/Dux/DuxTextView.m 내가 인정
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unable to convert bytes in string 0x10004d430 to _NSCStringEncoding'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff84afb286 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff88991d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff84afb0ba +[NSException raise:format:arguments:] + 106
3 CoreFoundation 0x00007fff84afb044 +[NSException raise:format:] + 116
4 Foundation 0x00007fff835bfae4 copyFromStringToStorage + 262
5 Foundation 0x00007fff835bf979 -[NSBigMutableString replaceCharactersInRange:withString:] + 1000
6 Foundation 0x00007fff835bc3f7 -[NSConcreteMutableAttributedString replaceCharactersInRange:withString:] + 375
7 AppKit 0x00007fff86149e14 -[NSConcreteTextStorage replaceCharactersInRange:withString:] + 81
8 Dux 0x0000000100002f9a -[MyTextDocument loadTextContentIntoStorage] + 1338
9 Dux 0x00000001000022a0 -[MyTextDocument windowControllerDidLoadNib:] + 640
10 AppKit 0x00007fff860f1328 -[NSWindowController _windowDidLoad] + 667
11 AppKit 0x00007fff860e89a3 -[NSWindowController window] + 109
12 AppKit 0x00007fff8615d761 -[NSDocument windowForSheet] + 86
13 AppKit 0x00007fff860e82c4 -[NSDocument _shouldShowAutosaveButtonForWindow:] + 50
14 AppKit 0x00007fff860e7fbb -[NSWindowController setDocument:] + 237
15 AppKit 0x00007fff8629c9b6 -[NSDocument makeWindowControllers] + 139
16 AppKit 0x00007fff8615d555 -[NSDocument(NSPersistentUISupport) restoreDocumentWindowWithIdentifier:state:completionHandler:] + 90
17 AppKit 0x00007fff8615d4aa -[NSDocumentControllerPersistentRestoration loadedDocument:forAutoID:] + 179
18 AppKit 0x00007fff8615cfbe __-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_8 + 187
19 AppKit 0x00007fff86148e14 __-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_5 + 163
20 AppKit 0x00007fff86148d5f __-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_4 + 697
21 AppKit 0x00007fff86148aa1 -[NSDocumentController _openDocumentWithContentsOfURL:usingProcedure:] + 530
22 AppKit 0x00007fff8614868d __-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_3 + 242
23 libdispatch.dylib 0x00007fff8bbbe8ba _dispatch_call_block_and_release + 18
24 libdispatch.dylib 0x00007fff8bbc072a _dispatch_main_queue_callback_4CF + 308
25 CoreFoundation 0x00007fff84a904dc __CFRunLoopRun + 1724
26 CoreFoundation 0x00007fff84a8fae6 CFRunLoopRunSpecific + 230
27 HIToolbox 0x00007fff8852f3d3 RunCurrentEventLoopInMode + 277
28 HIToolbox 0x00007fff8853663d ReceiveNextEventCommon + 355
29 HIToolbox 0x00007fff885364ca BlockUntilNextEventMatchingListInMode + 62
30 AppKit 0x00007fff85ef23f1 _DPSNextEvent + 659
31 AppKit 0x00007fff85ef1cf5 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135
32 AppKit 0x00007fff85eee62d -[NSApplication run] + 470
33 AppKit 0x00007fff8616d80c NSApplicationMain + 867
34 Dux 0x0000000100001e32 main + 34
35 Dux 0x0000000100001e04 start + 52
36 ??? 0x0000000000000003 0x0 + 3
)
메모리가 손상되었을 수 있습니다. XCode에서 사용할 수있는 메모리 일관성 도구를 사용해 보셨습니까? (Build and Analyze, Zombies, and ilk) – voidref
예, 빌드 및 분석을 시도했으며 좀비가 활성화되었습니다. ARC도 사용하고 있습니다. –
매혹적이어서 프로젝트에 참여했습니다. 나는 낙서 가드와 그 모든 것들을 가능하게했는데, 여전히 틀린 것을 찾지 못했습니다. 분석기에 표시되는 여러 가지 정당한 우려 사항이 있지만 문제를 수정해도이 문제에 영향을 미치지 않습니다. – voidref