macos - EXC_BAD_INSTRUCTION 在 Lion 中但不在 Mountain Lion 中

标签 macos cocoa osx-lion osx-mountain-lion

在 Lion 中打开窗口时,我遇到以下 EXC_BAD_INSTRUCTION 异常,但该应用在 Mountain Lion 中似乎工作正常。可能是什么问题?

Process:         MyApp [595]
Path:            /Users/USER/Desktop/MyApp.app/Contents/MacOS/MyApp
Identifier:      com.example.MyApp
Version:         ??? (0.4)
Code Type:       X86-64 (Native)
Parent Process:  launchd [146]

Date/Time:       2012-09-25 11:09:14.498 +0200
OS Version:      Mac OS X 10.7.3 (11D50d)
Report Version:  9
Sleep/Wake UUID: BA4DA964-60E8-4DC6-B63C-99435074A41C

Interval Since Last Report:          2901634 sec
Crashes Since Last Report:           367
Per-App Interval Since Last Report:  129923 sec
Per-App Crashes Since Last Report:   8
Anonymous UUID:                      BFF6E121-730D-4729-B07F-DA8550F46E14

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes: 0x0000000000000001, 0x0000000000000000

Application Specific Information:
objc[595]: garbage collection is OFF
objc[595]: cannot form weak reference to instance (0x7fc091666650) of class MyViewController
Performing @selector(startPressed:) from sender NSButton 0x7fc09167d210

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib                0x00007fff91496768 _objc_trap + 4
1   libobjc.A.dylib                0x00007fff914968aa _objc_fatal + 195
2   libobjc.A.dylib                0x00007fff914a24ad weak_register_no_lock + 346
3   libobjc.A.dylib                0x00007fff914a2a59 objc_storeWeak + 360
4   com.apple.CoreFoundation       0x00007fff8f29c75d -[NSObject performSelector:withObject:] + 61
5   com.apple.AppKit               0x00007fff94bb5392 -[NSNibOutletConnector establishConnection] + 405
6   com.apple.AppKit               0x00007fff94bb2a89 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 107

最佳答案

找到了。问题是我用 weak 声明了一个委托(delegate) id 属性,并为其分配了一个 NSVieWcontroller

显然,如果您想支持 Lion 并确保安全,则绝不应将 id 属性声明为 weak。从过渡到ARC Release Notes :

Note: In addition, in OS X v10.7, you cannot create weak references to instances of NSFontManager, NSFontPanel, NSImage, NSTableCellView, NSViewController, NSWindow, and NSWindowController. In addition, in OS X v10.7 no classes in the AV Foundation framework support weak references.

解决方案:使用分配代替。

@property (nonatomic, assign) IBOutlet id<MyDelegateProtocol> delegate;

关于macos - EXC_BAD_INSTRUCTION 在 Lion 中但不在 Mountain Lion 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12580784/

相关文章:

macos - weka mac安装

c++ - @class 和#imports 之间的区别

xcode - 卸载Lion中的XCode

iphone - 委托(delegate)与 cocoa 中的对象有何不同......?

mysql - 无法从 Mac lion 连接到远程 mysql

ruby - 无法在 OSX Lion 上使用 RVM 安装 Ruby Enterprise Edition

java - 访问限制 : The type 'Application' is not API (restriction on required library rt. jar)

objective-c - 在 Mac 上单击鼠标向下拖动对象

macos - 在 OS X 10.9 上设置 PATH 不起作用

JSON 数据不显示在 NSTableView 中