【问题标题】:libc++abi.dylib: terminating with uncaught exception of type NSException on iOS 7.1libc++abi.dylib:在 iOS 7.1 上以 NSException 类型的未捕获异常终止
【发布时间】:2014-12-29 21:47:00
【问题描述】:

我是编程新手。我将使用 Apple 新的编程语言 Swift 学习 iOS 应用程序开发。 我跟随这个网站(https://developer.apple.com/swift/blog/?id=16)开始。
我将视频中的代码复制到了我的 Xcode 项目中。当我在 iOS 8.1 iOS 模拟器中运行应用程序时,一切都很好。
但是我在选择 iOS 7.1 iOS 模拟器时遇到了异常。
然后我将应用程序放入我的 iPhone 5S(iOS 7.1.2),它崩溃了。

以下是我从视频中复制的代码:

import UIKit
class ViewController: UIViewController {
    @IBOutlet weak var photoImageView: UIImageView!
    let context = CIContext(options: nil)

    @IBAction func applyFilter(sender: AnyObject) {
        let inputImage = CIImage(image: photoImageView.image)

        let randomColor = [kCIInputAngleKey: (Double(arc4random_uniform(314)) / 100)]
        let filteredImage = inputImage.imageByApplyingFilter("CIHueAdjust",withInputParameters: randomColor)
        let renderedImage = context.createCGImage(filteredImage, fromRect: filteredImage.extent())

        photoImageView.image = UIImage(CGImage: renderedImage)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

这是我从控制台得到的:

2014-11-03 16:17:30.645 njnj[2748:60b] -[CIImage imageByApplyingFilter:withInputParameters:]: unrecognized selector sent to instance 0x7fe4e3d165e0
2014-11-03 16:17:30.649 njnj[2748:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CIImage imageByApplyingFilter:withInputParameters:]: unrecognized selector sent to instance 0x7fe4e3d165e0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000106c8b495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010852799e objc_exception_throw + 43
    2   CoreFoundation                      0x0000000106d1c65d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000106c7cd8d ___forwarding___ + 973
    4   CoreFoundation                      0x0000000106c7c938 _CF_forwarding_prep_0 + 120
    5   njnj                                0x0000000106b934a0 _TFC4njnj14ViewController11applyFilterfS0_FPSs9AnyObject_T_ + 3648
    6   njnj                                0x0000000106b93a66 _TToFC4njnj14ViewController11applyFilterfS0_FPSs9AnyObject_T_ + 54
    7   UIKit                               0x000000010753af06 -[UIApplication sendAction:to:from:forEvent:] + 80
    8   UIKit                               0x000000010753af06 -[UIApplication sendAction:to:from:forEvent:] + 80
    9   UIKit                               0x000000010753aeb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
    10  UIKit                               0x0000000107617880 -[UIControl _sendActionsForEvents:withEvent:] + 203
    11  UIKit                               0x0000000107616dc0 -[UIControl touchesEnded:withEvent:] + 530
    12  UIKit                               0x0000000107571d05 -[UIWindow _sendTouchesForEvent:] + 701
    13  UIKit                               0x00000001075726e4 -[UIWindow sendEvent:] + 925
    14  UIKit                               0x000000010754a29a -[UIApplication sendEvent:] + 211
    15  UIKit                               0x0000000107537aed _UIApplicationHandleEventQueue + 9579
    16  CoreFoundation                      0x0000000106c1ad21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    17  CoreFoundation                      0x0000000106c1a5f2 __CFRunLoopDoSources0 + 242
    18  CoreFoundation                      0x0000000106c3646f __CFRunLoopRun + 767
    19  CoreFoundation                      0x0000000106c35d83 CFRunLoopRunSpecific + 467
    20  GraphicsServices                    0x000000010baf2f04 GSEventRunModal + 161
    21  UIKit                               0x0000000107539e33 UIApplicationMain + 1010
    22  njnj                                0x0000000106b9582e top_level_code + 78
    23  njnj                                0x0000000106b9586a main + 42
    24  libdyld.dylib                       0x0000000108ee55fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

我希望有人能帮我解决这个问题。 (对不起我的英语不好)

【问题讨论】:

  • 崩溃日志抱怨imageByApplyingFilter:withInputParameters:。您是否在文档中查找过该功能?据developer.apple.com/library/ios/releasenotes/General/…称,它是在iOS 8.0中添加的。
  • @MartinR ,非常感谢。我只是用谷歌搜索“imageByApplyingFilter iOS 7.1”,但我没有找到任何我需要的东西。非常感谢。
  • 为什么不确保您的应用程序的Deployment Target 适合您希望运行应用程序的设备/模拟器版本?
  • @findall 部署目标已设置为 7.1

标签: ios iphone xcode ios7 swift


【解决方案1】:

通常“发送到实例的无法识别的选择器”(由 -doesNotRecognizeSelector 导致:)表示内存管理问题,通常是过度释放仍在某处引用的对象。

我建议您运行带有内存调试的调试版本,以对应用的内存问题进行分类。我建议您通过最新版本的 Xcode 使用 ASan。如果这不是一个选项,您可以将 malloc 历史记录与 guard malloc、scribble 和 NSZombies 一起使用。

【讨论】:

  • Zombies 帮助调试 BAD_ACCESS。无法识别的选择器意味着找不到您尝试调用的方法的签名。在 Xcode 中奇怪的是,当二进制文件(例如 .framework)未链接、嵌入或复制时,此错误会在运行时出现。特别是当方法属于某个类别时。
  • Zombies 有助于调试导致 BAD_ACCESS 的过度释放,因为它使对象保持活动状态以捕获这些访问。它还有助于调试导致 -doesNotRecognizeSelector: 的过度发布。当一个对象被释放(引用仍然存在)时,可以在该地址创建另一个对象,然后通过引用被释放对象的未来访问将触发 -doesNotRecognizeSelector:.
  • 我同意你的回答。您是否有一两个示例程序来演示这两种僵尸?或者也许是教程的链接?谢谢
猜你喜欢
  • 1970-01-01
  • 2015-09-08
  • 1970-01-01
  • 2014-12-14
  • 2014-10-04
  • 2017-05-25
  • 1970-01-01
  • 1970-01-01
  • 2017-02-06
相关资源
最近更新 更多