Aggressor
Aggressor

Reputation: 13551

Getting EXC_BAD_ACESS code =1 When Trying To Capture An Image From Camera

New issue has come up as I've moved to Swift. This code worked in Objc but now its broken.

  func captureImage()
    {
        var videoConnection:AVCaptureConnection = AVCaptureConnection()
        for connection in _stillImageOutput.connections
        {

        }
    }

For some reason, if I run the above loop I get an EXC_BAD_ACCESS code 1 on the last line. enter image description here

_stillImageOutput is just an AVCaptureStillImage object and its not nil

Commenting out the var videoConnection:AVCaptureConnection = AVCaptureConnection() stops this crash.

Any ideas?

Upvotes: 0

Views: 75

Answers (1)

Aggressor
Aggressor

Reputation: 13551

Turns out had nothing to do with the for loop

Doing var videoConnection:AVCaptureConnection = AVCaptureConnection() is what caused the crash.

Changing it to var videoConnection:AVCaptureConnection! fixed the issue

Upvotes: 0

Related Questions