diff main/PreferencesDialog.cpp @ 1415:13eb1d55f129 3.0-integration

Avoid overflowing vector if number of devices becomes smaller
author Chris Cannam
date Mon, 12 Dec 2016 17:01:16 +0000
parents a89ca5ccb958
children 8bff263578ae
line wrap: on
line diff
--- a/main/PreferencesDialog.cpp	Mon Dec 12 15:46:53 2016 +0000
+++ b/main/PreferencesDialog.cpp	Mon Dec 12 17:01:16 2016 +0000
@@ -875,6 +875,9 @@
 
     vector<string> names = breakfastquay::AudioFactory::getImplementationNames();
     string implementationName;
+    if (m_audioImplementation > int(names.size())) {
+        m_audioImplementation = 0;
+    }
     if (m_audioImplementation > 0) {
         implementationName = names[m_audioImplementation-1];
     }
@@ -887,6 +890,9 @@
     
     names = breakfastquay::AudioFactory::getPlaybackDeviceNames(implementationName);
     string deviceName;
+    if (m_audioPlaybackDevice > int(names.size())) {
+        m_audioPlaybackDevice = 0;
+    }
     if (m_audioPlaybackDevice > 0) {
         deviceName = names[m_audioPlaybackDevice-1];
     }
@@ -894,6 +900,9 @@
 
     names = breakfastquay::AudioFactory::getRecordDeviceNames(implementationName);
     deviceName = "";
+    if (m_audioRecordDevice > int(names.size())) {
+        m_audioRecordDevice = 0;
+    }
     if (m_audioRecordDevice > 0) {
         deviceName = names[m_audioRecordDevice-1];
     }
@@ -922,6 +931,7 @@
 
     if (m_audioDeviceChanged) {
         emit audioDeviceChanged();
+        m_audioDeviceChanged = false;
     }
 }