简体   繁体   English

无法调试EXC BAD ACCESS代码1

[英]Unable to debug EXC BAD ACCESS Code 1

Thanks for checking out my post. 感谢您查看我的帖子。

So on line image!.drawInRect(rect!) , I get the EXC_BAD_ACCESS Code 1 error and I can't figure it out for the life of me. 因此,在image!.drawInRect(rect!) ,我得到EXC_BAD_ACCESS代码1错误,我无法终生解决。 I have enabled Zombies in the Run Scheme, and nothing prints out (maybe I'm doing that wrong too?), I have println() seemingly all of my variables and nothing is nil. 我在“运行方案”中启用了“僵尸”功能,但没有输出任何内容(也许我也做错了吗?),我似乎拥有所有的变量println(),并且没有零。

I would like to note that this code works twice and then fails the 3rd time it is called, majority of the time. 我想指出,这段代码工作两次,然后在大多数情况下第三次被调用失败。 In my app, you take a picture, then it takes you to edit the picture (when this function is called). 在我的应用程序中,您需要拍照,然后需要编辑图片(调用此功能时)。 When I go back to my camera to take a picture, and return to edit it (on the 3rd time), I get this error. 当我回到相机拍照并返回进行编辑(第3次)时,出现此错误。

Also, this method is called in viewDidAppear() 另外,此方法在viewDidAppear()调用

Any help is appreciated. 任何帮助表示赞赏。 I'm about to pull my hair out! 我要拔头发了!

       var rect: CGRect?
    var image: UIImage?
func convertCIImageToUIImage(cIImage: CIImage) -> UIImage {

    println(cIImage)

    let size: CGSize = filteredImageView.inputImage.size
    println(filteredImageView.inputImage.size)

    UIGraphicsBeginImageContext(size)

    rect = CGRect(origin: CGPointZero, size: size)
    image = UIImage(CIImage: filteredImageView.filter.outputImage)

    println(UIGraphicsGetCurrentContext())
    println("size: \(size)")
    printAllObjects()
    println()

    image!.drawInRect(rect!)
    let newImage = UIGraphicsGetImageFromCurrentImageContext()

    UIGraphicsEndImageContext()

    image = nil
    rect = nil

    let finalImage = UIImage(CGImage: newImage.CGImage!, scale: 1.0, orientation: UIImageOrientation.Right)
    return finalImage!
}

Solved it! 解决了!

My function was over-engineered by a long-shot. 我的功能过分精心设计。 A simple return UIImage(CIImage: cIImage)! 一个简单的return UIImage(CIImage: cIImage)! solved my problem and replaced all of the code above. 解决了我的问题,并替换了上面的所有代码。 That's what I get for copying code online! 这就是我在线复制代码所获得的! Lesson learned. 学过的知识。 Thanks for the help! 谢谢您的帮助!

Since the line in question force-unwraps two optionals maybe you're unwrapping a nil (which generates the error). 由于所讨论的行强制展开两个可选内容,因此您可能要解包一个nil(这会产生错误)。 Try using optional binding for safe unwrapping: 尝试使用可选绑定来安全展开:

if let safeRect = CGRect(origin: CGPointZero, size: size),
   let safeImage = UIImage(CIImage: filteredImageView.filter.outputImage)
{
   safeImage.drawInRect(safeRect)
}

This way, if construction of either the CGRect instance or the UIImage instance fails, the line inside braces won't be executed. 这样,如果CGRect实例或UIImage实例的构建失败,则不会执行大括号内的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM