From 3baf3eae65fc522aad9befeb0b51b49010c162c2 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Sun, 15 Jan 2023 11:14:28 +0000 Subject: [PATCH] Fix crash when no audio device is found --- audiodevices.cpp | 6 ++++-- wfmain.cpp | 38 +++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/audiodevices.cpp b/audiodevices.cpp index 1d24227..ee5be46 100644 --- a/audiodevices.cpp +++ b/audiodevices.cpp @@ -355,6 +355,7 @@ int audioDevices::findInput(QString type, QString name) int usb = -1; QString msg; QTextStream s(&msg); + for (int f = 0; f < inputs.size(); f++) { //qInfo(logAudio()) << "Found device" << inputs[f].name; @@ -391,7 +392,7 @@ int audioDevices::findInput(QString type, QString name) ret = def; } else { - s << " and no default device found, aborting!"; + s << " and no default device found, aborting!"; } } @@ -406,6 +407,7 @@ int audioDevices::findOutput(QString type, QString name) int usb = -1; QString msg; QTextStream s(&msg); + for (int f = 0; f < outputs.size(); f++) { //qInfo(logAudio()) << "Found device" << outputs[f].name; @@ -448,4 +450,4 @@ int audioDevices::findOutput(QString type, QString name) } qInfo(logAudio()) << msg; return ret; -} \ No newline at end of file +} diff --git a/wfmain.cpp b/wfmain.cpp index 1cd6317..8e35496 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -2400,7 +2400,7 @@ void wfmain::on_serverAudioPortText_textChanged(QString text) void wfmain::on_serverRXAudioInputCombo_currentIndexChanged(int value) { - if (!serverConfig.rigs.isEmpty()) + if (!serverConfig.rigs.isEmpty() && value>=0) { if (prefs.audioSystem == qtAudio) { serverConfig.rigs.first()->rxAudioSetup.port = audioDev->getInputDeviceInfo(value); @@ -2417,7 +2417,7 @@ void wfmain::on_serverRXAudioInputCombo_currentIndexChanged(int value) void wfmain::on_serverTXAudioOutputCombo_currentIndexChanged(int value) { - if (!serverConfig.rigs.isEmpty()) + if (!serverConfig.rigs.isEmpty() && value>=0) { if (prefs.audioSystem == qtAudio) { serverConfig.rigs.first()->txAudioSetup.port = audioDev->getOutputDeviceInfo(value); @@ -5623,29 +5623,31 @@ void wfmain::on_passwordTxt_textChanged(QString text) void wfmain::on_audioOutputCombo_currentIndexChanged(int value) { - if (prefs.audioSystem == qtAudio) { - rxSetup.port = audioDev->getOutputDeviceInfo(value); - } - else { - rxSetup.portInt = audioDev->getOutputDeviceInt(value); - } + if (value>=0) { + if (prefs.audioSystem == qtAudio) { + rxSetup.port = audioDev->getOutputDeviceInfo(value); + } + else { + rxSetup.portInt = audioDev->getOutputDeviceInt(value); + } - rxSetup.name = audioDev->getOutputName(value); + rxSetup.name = audioDev->getOutputName(value); + } qDebug(logGui()) << "Changed audio output to:" << rxSetup.name; } void wfmain::on_audioInputCombo_currentIndexChanged(int value) { + if (value >=0) { + if (prefs.audioSystem == qtAudio) { + txSetup.port = audioDev->getInputDeviceInfo(value); + } + else { + txSetup.portInt = audioDev->getInputDeviceInt(value); + } - if (prefs.audioSystem == qtAudio) { - txSetup.port = audioDev->getInputDeviceInfo(value); + txSetup.name = audioDev->getInputName(value); } - else { - txSetup.portInt = audioDev->getInputDeviceInt(value); - } - - txSetup.name = audioDev->getInputName(value); - qDebug(logGui()) << "Changed audio input to:" << txSetup.name; } @@ -6808,6 +6810,7 @@ void wfmain::on_radioStatusBtn_clicked() void wfmain::setAudioDevicesUI() { + qInfo() << "Looking for inputs"; ui->audioInputCombo->blockSignals(true); ui->audioInputCombo->clear(); ui->audioInputCombo->addItems(audioDev->getInputs()); @@ -6816,6 +6819,7 @@ void wfmain::setAudioDevicesUI() ui->audioInputCombo->blockSignals(false); ui->audioInputCombo->setCurrentIndex(audioDev->findInput("Client", txSetup.name)); + qInfo() << "Looking for outputs"; ui->audioOutputCombo->blockSignals(true); ui->audioOutputCombo->clear(); ui->audioOutputCombo->addItems(audioDev->getOutputs());