0

I'm having an issue attempting to debug a malloc error/memory leak. Heres what my code looks like:

class UploadPostController: UITableViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, TOCropViewControllerDelegate {

var myPickerController : UIImagePickerController?

override func viewDidLoad() {
    super.viewDidLoad()

}

override func viewWillLayoutSubviews() {
    setupNavBarButtons()
}

func setupNavBarButtons() {
    let uploadBarButtonItem = UIBarButtonItem(title: "Upload", style: .plain, target: self, action: #selector(displayImagePickerButtonTapped))
    navigationItem.rightBarButtonItem = uploadBarButtonItem
}

func displayImagePickerButtonTapped() {

    myPickerController = UIImagePickerController()
    myPickerController?.delegate = self
    myPickerController?.sourceType = UIImagePickerControllerSourceType.photoLibrary
    self.present(myPickerController!, animated: true, completion: nil) // crashes here.
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage{
        let cropVC = TOCropViewController(image: pickedImage)
        cropVC.delegate = self
        cropVC.aspectRatioPickerButtonHidden = true
        cropVC.aspectRatioPreset = .presetSquare
        cropVC.aspectRatioLockEnabled = true
        cropVC.resetAspectRatioEnabled = false
        myPickerController?.pushViewController(cropVC, animated: true)
    }
}

func cropViewController(_ cropViewController: TOCropViewController, didCropToImage image: UIImage, rect cropRect: CGRect, angle: Int) {
    self.arrayOfCroppedImages.append(image)
    dismiss(animated: true, completion: nil)
    myPickerController = nil
}
}

I've took a lot of the code out of the file as I can't see any of the other stuff being relevant. It crashes when I'm attempting to present the UIImagePickerController

I have set a malloc_error_break breakpoint and this is what I get back enter image description here

The crash is completely random. Probably around a 15% chance of occurring

luke
  • 2,743
  • 4
  • 19
  • 43
  • this happened to me too, is this only on simulator or on device? – Aakash May 29 '17 at 18:17
  • `UIPickerViewController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary )` returns true? – Larme May 29 '17 at 18:33
  • @Aakash I believe so if I recall correctly. I'll make sure now – luke May 29 '17 at 18:37
  • @Larme yeah returns true – luke May 29 '17 at 18:37
  • @Larme I also tried this code here to verify access but didn't change anything: https://stackoverflow.com/questions/41135701/app-crashed-due-to-invalid-signature-for-pointer-dequeued-from-free-list-in-uiim?noredirect=1#comment75486560_41135701 – luke May 29 '17 at 18:39

0 Answers0