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
The crash is completely random. Probably around a 15% chance of occurring