NSTextField 绑定导致 EXC_BAD_ACCESS

发布于 2024-09-12 01:59:23 字数 4776 浏览 7 评论 0原文

我有一个 NSTextField,它绑定到我包含在笔尖中的对象中的 int 。当对象更改其 int 时,文本字段也会随之更改,一切看起来都很好。

但是,当我尝试手动更改它时,一旦按下某个键,程序就会崩溃。它甚至没有进入我的 setter 方法,它只是崩溃了

Program received signal:  “EXC_BAD_ACCESS”.

It's not甚至在我的任何代码中......大概,我做了错误的绑定,但我能做什么,会使其出现这样的段错误?

ETA:崩溃时的堆栈帧:

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

确实有一个文档类,它是NSDocument的子类,并且文本字段绑定到该文档对象的字段,但我'我不确定为什么这很重要。

I have an NSTextField which is bound to an int in an object that I have included in my nib. When the object changes its int, the text field follows suit, and everything looks fine.

However, when I try to change it manually the program crashes as soon as I hit a key. It's not even getting into my setter methods, it just crashes with

Program received signal:  “EXC_BAD_ACCESS”.

It's not even in any of my code... presumably, I made the binding wrong, but what could I have done that would make it segfault like that?

ETA: stackframes from a crash:

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

I DO have a document class that is subclassed off of NSDocument, and the textfield IS bound to a field of that document object, but I'm not sure why that would matter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里寻她 2024-09-19 01:59:23

环境变量 NSBindingDebugLogLevel 可能有用。设置它并仔细检查日志中是否有警告。如果您在 NSException 引发时设置了断点,您可能不会看到警告。

绑定应该与 int 一起使用,绝对不能与 unsigned int 一起使用。但 NSTextfield 需要一个 NSString,或者至少需要一个 NSNumber 和一个关联的 NSNumberFormatter。

The environment variable NSBindingDebugLogLevel might be useful. Set it and check your logs carefully for warnings. You might not see the warning if you have a breakpoint set on NSException raise.

Bindings should work with an int, definitely not with an unsigned int. But NSTextfield requires an NSString, or at least an NSNumber and an associated NSNumberFormatter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文