Prevent crash when there is no camera device available
authorAndy Shaw <andy.shaw@digia.com>
Wed, 19 Mar 2014 09:41:46 +0000 (10:41 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 19 Mar 2014 09:56:30 +0000 (10:56 +0100)
If you try to use QAudioInputSelectorControl with the iOS Simulator then
it would crash as there is no camera device available. This prevents a
crash from happening in that case.

Change-Id: I3904f3d299a11a6df21e66a1138a4319cc0b8a5c
Reviewed-by: Andy Nichols <andy.nichols@digia.com>
src/plugins/avfoundation/camera/avfaudioinputselectorcontrol.mm

index 6c6df51..4a2f068 100644 (file)
@@ -60,7 +60,8 @@ AVFAudioInputSelectorControl::AVFAudioInputSelectorControl(AVFCameraService *ser
                                     QString::fromUtf8([[device localizedName] UTF8String]));
     }
 
-    m_activeInput = m_devices.first();
+    if (m_devices.size() > 0)
+        m_activeInput = m_devices.first();
 }
 
 AVFAudioInputSelectorControl::~AVFAudioInputSelectorControl()
@@ -79,7 +80,7 @@ QString AVFAudioInputSelectorControl::inputDescription(const QString &name) cons
 
 QString AVFAudioInputSelectorControl::defaultInput() const
 {
-    return m_devices.first();
+    return m_devices.size() > 0 ? m_devices.first() : QString();
 }
 
 QString AVFAudioInputSelectorControl::activeInput() const