0

I'm am getting this error on a app I'm making but only on iPhone 4s and iPad 2 EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0x0)

The error causes a breakpoint when I'm incrementing an integer

colorNum++

which doesn't make sense to me

I think it might be because of a web:complete function i call from this code: Does anyone know how to fix this

    var session = NSURLSession.sharedSession()

    var task = session.dataTaskWithURL(urlPath!) {
        data, response, error -> Void in
        if ((error) != nil) {
            println(error!.localizedDescription)
        }
        var jsonError : NSError?
        var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &jsonError) as? Dictionary<String, AnyObject>
        if (jsonError != nil) {
            println(jsonError!.localizedDescription)
        }

        if let apiDel = self.delegate? {
            if ((jsonResult) != nil) {
                dispatch_async(dispatch_get_main_queue(), {
                    apiDel.didFinishGettingHorror(jsonResult!)
                    self.pageNum++
                })
            }
        }
    }
    task.resume()
}

1 Answers1

0

I assume your pageNum variable is (implicitly) declared to be of type Int. iPhone 4S, iPhone 5, iPad 2, iPad Retina are 32-bit devices, where Int is a 32-bit integer. When you increment pageNum, you might actually making it overflow, which results in EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0x0).

See iOS Swift - EXC_BAD_INSTRUCTION on certain devices.

I had the same issue. Having read both this thread and the one I linked above made me realise what was the problem.

Community
  • 1
  • 1
pingd
  • 118
  • 11