From 024c8414155e39b64e23066f1335166cee70a9a7 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Fri, 7 Mar 2014 14:15:13 +0100 Subject: AVFoundation: fix crash when no camera is available on the system. Change-Id: I0b473babae4d1fae605667957deca21ba1dc0c09 Reviewed-by: Andy Nichols --- src/plugins/avfoundation/camera/avfvideodevicecontrol.mm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plugins/avfoundation/camera/avfvideodevicecontrol.mm b/src/plugins/avfoundation/camera/avfvideodevicecontrol.mm index d049859c..03736c39 100644 --- a/src/plugins/avfoundation/camera/avfvideodevicecontrol.mm +++ b/src/plugins/avfoundation/camera/avfvideodevicecontrol.mm @@ -66,7 +66,7 @@ int AVFVideoDeviceControl::deviceCount() const QString AVFVideoDeviceControl::deviceName(int index) const { const QList &devices = AVFCameraSession::availableCameraDevices(); - if (index >= devices.count()) + if (index < 0 || index >= devices.count()) return QString(); return QString::fromUtf8(devices.at(index)); @@ -75,7 +75,7 @@ QString AVFVideoDeviceControl::deviceName(int index) const QString AVFVideoDeviceControl::deviceDescription(int index) const { const QList &devices = AVFCameraSession::availableCameraDevices(); - if (index >= devices.count()) + if (index < 0 || index >= devices.count()) return QString(); return AVFCameraSession::cameraDeviceInfo(devices.at(index)).description; @@ -93,7 +93,9 @@ int AVFVideoDeviceControl::selectedDevice() const void AVFVideoDeviceControl::setSelectedDevice(int index) { - if (index != m_selectedDevice) { + if (index >= 0 && + index < deviceCount() && + index != m_selectedDevice) { m_dirty = true; m_selectedDevice = index; Q_EMIT selectedDeviceChanged(index); -- cgit v1.2.3