2010-07-28 119 views
0

我有一個NSTextField綁定到一個int我已經包含在我的筆尖對象。當對象改變它的int值時,文本字段會跟隨,並且一切看起來都很好。NSTextField綁定導致EXC_BAD_ACCESS

但是,當我嘗試手動更改它時,程序崩潰,只要我按一個鍵。它甚至沒有進入我的設置方法,它只是

Program received signal: 「EXC_BAD_ACCESS」. 

崩潰,它甚至不是在我的任何代碼......大概,我做了綁定錯了,但我能怎麼做了,將使它段錯誤像那樣?

ETA:從崩潰stackframes:

Process:   DocKeep [77998] 
Path:   /Users/acordex/Documents/projects/DocKeep/build/Debug/DocKeep.app/Contents/MacOS/DocKeep 
Identifier:  com.acordex.DocKeep 
Version:   9.00 pre-Alpha (9.00 pre-Alpha) 
Code Type:  X86 (Native) 
Parent Process: Instruments [77954] 

Date/Time:  2010-07-29 10:01:11.927 -0400 
OS Version:  Mac OS X 10.6.4 (10F569) 
Report Version: 6 

Exception Type: EXC_BAD_ACCESS (SIGBUS) 
Exception Codes: KERN_PROTECTION_FAILURE at 0x000000000000001c 
Crashed Thread: 0 Dispatch queue: com.apple.main-thread 

Thread 0 Crashed: Dispatch queue: com.apple.main-thread 
0 com.apple.AppKit    0x954a4734 -[NSDocument(NSEditorRegistration) _isBeingEdited] + 24 
1 com.apple.AppKit    0x954a4707 -[NSDocument isDocumentEdited] + 47 
2 com.apple.AppKit    0x955b3900 -[NSDocument(NSEditorRegistration) objectDidBeginEditing:] + 48 
3 com.apple.AppKit    0x95461ef9 -[NSValueBinder _startChanging] + 126 
4 com.apple.AppKit    0x95461dc1 -[NSTextValueBinder _startChanging] + 60 
5 com.apple.AppKit    0x95461d5f -[_NSBindingAdaptor _editor:didChangeEditingState:bindingAdaptor:] + 181 
6 com.apple.AppKit    0x95461c9f -[_NSBindingAdaptor editorDidBeginEditing:] + 278 
7 com.apple.AppKit    0x95442e5a -[NSTextField textShouldBeginEditing:] + 239 
8 com.apple.AppKit    0x95441d0b -[NSTextView(NSSharing) shouldChangeTextInRanges:replacementStrings:] + 573 
9 com.apple.AppKit    0x95464563 _NSDoUserReplaceForCharRange + 191 
10 com.apple.AppKit    0x9546449e _NSDoUserDeleteForCharRange + 79 
11 com.apple.AppKit    0x95463b07 -[NSTextView(NSKeyBindingCommands) deleteBackward:] + 684 
12 com.apple.AppKit    0x9544b364 -[NSResponder doCommandBySelector:] + 77 
13 com.apple.AppKit    0x9544ac7f -[NSTextView doCommandBySelector:] + 240 
14 com.apple.AppKit    0x95439bbf -[NSKeyBindingManager(NSKeyBindingManager_MultiClients) interpretEventAsCommand:forClient:] + 1911 
15 com.apple.AppKit    0x9543d44f -[NSTextInputContext handleEvent:] + 1604 
16 com.apple.AppKit    0x95439229 -[NSView interpretKeyEvents:] + 209 
17 com.apple.AppKit    0x9543ccd5 -[NSTextView keyDown:] + 751 
18 com.apple.AppKit    0x9536df6c -[NSWindow sendEvent:] + 5757 
19 com.apple.AppKit    0x95286aff -[NSApplication sendEvent:] + 6431 
20 com.apple.AppKit    0x9521a5bb -[NSApplication run] + 917 
21 com.apple.AppKit    0x952125ed NSApplicationMain + 574 
22 com.acordex.DocKeep    0x0000224c main + 30 (main.m:14) 
23 com.acordex.DocKeep    0x00002202 start + 54 

Thread 1: 
0 libSystem.B.dylib    0x94a319d2 __workq_kernreturn + 10 
1 libSystem.B.dylib    0x94a31f68 _pthread_wqthread + 941 
2 libSystem.B.dylib    0x94a31b86 start_wqthread + 30 

Thread 2: Dispatch queue: com.apple.libdispatch-manager 
0 libSystem.B.dylib    0x94a32942 kevent + 10 
1 libSystem.B.dylib    0x94a3305c _dispatch_mgr_invoke + 215 
2 libSystem.B.dylib    0x94a32519 _dispatch_queue_invoke + 163 
3 libSystem.B.dylib    0x94a322be _dispatch_worker_thread2 + 240 
4 libSystem.B.dylib    0x94a31d41 _pthread_wqthread + 390 
5 libSystem.B.dylib    0x94a31b86 start_wqthread + 30 

Thread 3: 
0 libSystem.B.dylib    0x94a3a066 __semwait_signal + 10 
1 libSystem.B.dylib    0x94a39d22 _pthread_cond_wait + 1191 
2 libSystem.B.dylib    0x94a3b9b8 pthread_cond_wait$UNIX2003 + 73 
3 com.apple.CoreVideo    0x96730c3e CVDisplayLink::runIOThread() + 1016 
4 com.apple.CoreVideo    0x9673082a startIOThread(void*) + 156 
5 libSystem.B.dylib    0x94a3981d _pthread_start + 345 
6 libSystem.B.dylib    0x94a396a2 thread_start + 34 

Thread 0 crashed with X86 Thread State (32-bit): 
    eax: 0x00000000 ebx: 0x954a472d ecx: 0x00000001 edx: 0x00000000 
    edi: 0x0045f650 esi: 0x0045f650 ebp: 0xbfffe738 esp: 0xbfffe720 
    ss: 0x0000001f efl: 0x00010282 eip: 0x954a4734 cs: 0x00000017 
    ds: 0x0000001f es: 0x0000001f fs: 0x00000000 gs: 0x00000037 
    cr2: 0x0000001c 

DO有子類是關閉的NSDocument文檔類和文本框綁定到文檔對象的一個​​領域,但我不知道爲什麼這很重要。

+1

你還沒有給我們太多的工作。即使堆棧不在您的代碼中,即使發佈堆棧跟蹤的前幾幀也會有所幫助。 「手動更改」是什麼意思?你的意思是通過代碼改變整型值嗎?然後告訴我們那個代碼。 首先猜測會是內存管理錯誤。嘗試運行殭屍儀器,同時再現崩潰。 – 2010-07-29 03:44:31

+0

不,手動更改意味着點擊文本框並輸入一個字符或點擊退格。當我從代碼中更改int時,它效果很好。我會嘗試殭屍併發布堆棧跟蹤。這是一個好主意。 – 2010-07-29 13:37:30

+0

我在運行殭屍時看不到任何東西。現在發佈stackframes。 – 2010-07-29 14:04:05

回答

0

環境變量NSBindingDebugLogLevel可能很有用。設置它並仔細檢查日誌以獲取警告。如果您在NSException raise中設置了斷點,則可能看不到警告。

綁定應該使用int,絕對不能使用unsigned int。但是NSTextfield需要一個NSString,或者至少一個NSNumber和一個關聯的NSNumberFormatter。