Commit 024c8414 authored by Yoann Lopes's avatar Yoann Lopes Committed by The Qt Project
Browse files

AVFoundation: fix crash when no camera is available on the system.


Change-Id: I0b473babae4d1fae605667957deca21ba1dc0c09
Reviewed-by: default avatarAndy Nichols <andy.nichols@digia.com>
Showing with 5 additions and 3 deletions
......@@ -66,7 +66,7 @@ int AVFVideoDeviceControl::deviceCount() const
QString AVFVideoDeviceControl::deviceName(int index) const
{
const QList<QByteArray> &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<QByteArray> &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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment