From 1286300a4c847e7fb08410ee6052ba2dcc7b7de2 Mon Sep 17 00:00:00 2001 From: Andy Nichols Date: Tue, 4 Mar 2014 14:11:01 +0100 Subject: AVFoundation: Cleanup AVCaptureSession with proper reference counting The reference counting was not being done for AVCaptureSession so it was being destroyed before we got a chance to properly clean it up (which lead to crashes). We also make sure to remove any observers from AVCaptureSession now before destroying it. Task-number: QTBUG-37109 Task-number: QTBUG-29955 Change-Id: Ia9b49ad1eab01b4f7424e2a1c699d903cd9bf902 Reviewed-by: Yoann Lopes --- src/plugins/avfoundation/camera/avfcamerasession.mm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/plugins/avfoundation/camera/avfcamerasession.mm') diff --git a/src/plugins/avfoundation/camera/avfcamerasession.mm b/src/plugins/avfoundation/camera/avfcamerasession.mm index 042855aa4..a72ef5041 100644 --- a/src/plugins/avfoundation/camera/avfcamerasession.mm +++ b/src/plugins/avfoundation/camera/avfcamerasession.mm @@ -85,6 +85,7 @@ QMap AVFCameraSession::m_cameraInfo; self->m_session = session; self->m_captureSession = session->captureSession(); + [m_captureSession retain]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(processRuntimeError:) name:AVCaptureSessionRuntimeErrorNotification @@ -103,6 +104,22 @@ QMap AVFCameraSession::m_cameraInfo; return self; } +- (void) dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self + name:AVCaptureSessionRuntimeErrorNotification + object:m_captureSession]; + + [[NSNotificationCenter defaultCenter] removeObserver:self + name:AVCaptureSessionDidStartRunningNotification + object:m_captureSession]; + + [[NSNotificationCenter defaultCenter] removeObserver:self + name:AVCaptureSessionDidStopRunningNotification + object:m_captureSession]; + [m_captureSession release]; + [super dealloc]; +} - (void) processRuntimeError:(NSNotification *)notification { -- cgit v1.2.3