2010-07-28 117 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。