Try to fix crashes when things go wrong with getDeviceInfo.
[dcpomatic.git] / src / wx / config_dialog.cc
index 0a546dc91f3cfa4be582864ff0a70555b2829e88..352c8ae482d73f1fba9b693de3953334a4a45817 100644 (file)
@@ -878,9 +878,17 @@ SoundPage::setup ()
 
        RtAudio audio (DCPOMATIC_RTAUDIO_API);
        for (unsigned int i = 0; i < audio.getDeviceCount(); ++i) {
-               RtAudio::DeviceInfo dev = audio.getDeviceInfo (i);
-               if (dev.probed && dev.outputChannels > 0) {
-                       _sound_output->Append (std_to_wx (dev.name));
+               try {
+                       RtAudio::DeviceInfo dev = audio.getDeviceInfo (i);
+                       if (dev.probed && dev.outputChannels > 0) {
+                               _sound_output->Append (std_to_wx (dev.name));
+                       }
+#ifdef DCPOMATIC_USE_RTERROR
+               } catch (RtError&) {
+#else
+               } catch (RtAudioError&) {
+#endif
+                       /* Something went wrong so let's just ignore that device */
                }
        }
 
@@ -913,7 +921,13 @@ SoundPage::sound_output_changed ()
 {
        RtAudio audio (DCPOMATIC_RTAUDIO_API);
        optional<string> const so = get_sound_output();
-       if (!so || *so == audio.getDeviceInfo(audio.getDefaultOutputDevice()).name) {
+       string default_device;
+       try {
+               default_device = audio.getDeviceInfo(audio.getDefaultOutputDevice()).name;
+       } catch (RtAudioError&) {
+               /* Never mind */
+       }
+       if (!so || *so == default_device) {
                Config::instance()->unset_sound_output ();
        } else {
                Config::instance()->set_sound_output (*so);