title: App crashes if I apply a CIFilter to a CIImage - Swift 2.0
body: <p>I have this strange problem I can't solve. If I take a picture with my app and apply a CIFilter to it everything works fine, but if I take another picture and apply the same filter my app crashes without any error. But strangely I can do the same process with a image from my camera roll and the app works perfectly fine.</p>
  
  <pre><code>//CAMERA
  
  @IBOutlet weak var imageView: UIImageView!
  
  var selectedImage: UIImage!    
  
  @IBAction func rollButtonPressed(sender: UIBarButtonItem) {
      let picker = UIImagePickerController()
  
      picker.delegate = self
      picker.sourceType = .PhotoLibrary
  
      self.presentViewController(picker, animated: true, completion: nil)
  }
  
  @IBAction func cameraButtonPressed(sender: UIBarButtonItem) {
      if UIImagePickerController.isSourceTypeAvailable(.Camera){
  
          let camera = UIImagePickerController()
          camera.delegate = self
          camera.allowsEditing = false
          camera.sourceType = UIImagePickerControllerSourceType.Camera
          camera.showsCameraControls = true
  
          camera.cameraOverlayView?.layer.borderWidth = 3
          camera.cameraOverlayView?.layer.borderColor = UIColor.redColor().CGColor
          camera.cameraOverlayView?.frame = CGRectMake(self.view.frame.minX, self.view.frame.midY - self.view.frame.width/8, self.view.frame.width, self.view.frame.width/4)
  
  
          self.presentViewController(camera, animated: true, completion: nil)
      }
  
  }
  
  func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
  
      self.dismissViewControllerAnimated(true, completion: nil)
  
      selectedImage = (info[UIImagePickerControllerOriginalImage] as! UIImage)
  
      for var i = 2; i &lt;= 10; i++ {
          imageView.image = processImage(selectedImage, colors: i)
      }
  
  }
  </code></pre>
  
  <p>The function that is causing the problems:</p>
  
  <pre><code>let context = CIContext(options: nil)
  
  func processImage(image: UIImage, colors: Int) -&gt; UIImage{
  
      var img1:CIImage = CIImage(image: image)!
      img1 = img1.imageByApplyingFilter("CIPhotoEffectMono", withInputParameters:["inputImage" : img1])
      img1 = img1.imageByApplyingFilter("CISharpenLuminance", withInputParameters: ["inputImage" : img1])
      img1 = img1.imageByApplyingFilter("CIColorPosterize", withInputParameters: ["inputImage" : img1, "inputLevels" : colors])
      img1 = img1.imageByApplyingFilter("CIColorControls", withInputParameters: ["inputImage" : img1, "inputSaturation" : 1, "inputBrightness": 0.2, "inputContrast": 1.5 //8
          ])
      img1 = img1.imageByApplyingFilter("CIHighlightShadowAdjust", withInputParameters: ["inputImage" : img1, "inputHighlightAmount": 6, "inputShadowAmount": 0])
      img1 = img1.imageByApplyingFilter("CIColorPosterize", withInputParameters: ["inputImage" : img1, "inputLevels" : 3])
  
  
      let cgImg = context.createCGImage(img1, fromRect: img1.extent)
  
      let uiImg = UIImage(CGImage: cgImg, scale: 1.0, orientation: image.imageOrientation)
      print("x")
      return uiImg
  }
  </code></pre>
  
  <p>I've looked at the RAM usage and if I use a image from the camera my app uses about 40% and the it crashes, but if I select a image from my camera roll I only get a max. of 8% of RAM usage. </p>
  
  <p>If you know why, I would be very happy if you could leave an answer.</p>