Fix crash on mac os during download from new BLE computer

Ensure that any bluetooth scan started (by changing the device name) in the
download-from-dive-computer dialog (desktop version) is stopped before the
download process is started up. Because the QT bluetooth discovery agent uses
a QTimer internally, it must be stopped from the same thread as it was started
from. The download process uses a different thread, so ends up crashing when
it tries to dispose of the timer from a different thread.

Reported-by: Steve Buie <sbuie321@gmail.com>
Signed-off-by: Steve Buie <sbuie321@gmail.com>
This commit is contained in:
stevebuie 2024-06-24 16:01:12 -06:00 committed by Michael Keller
parent 1b4111c1f8
commit 8f4f8fe489

View file

@ -365,7 +365,7 @@ void DownloadFromDCWidget::on_product_currentTextChanged(const QString &)
void DownloadFromDCWidget::on_device_currentTextChanged(const QString &device)
{
#if defined(Q_OS_MACOS)
#if defined(BT_SUPPORT) && defined(Q_OS_MACOS)
if (isBluetoothAddress(device)) {
// ensure we have a discovery running
if (btd == nullptr)
@ -430,6 +430,16 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
data->setDevName(address);
data->setDevBluetoothName(name);
}
if (btd) {
// btd should only be active for mac os.
// Need to ensure that any scan is shut down BEFORE starting the download
// because internally (as of 5.15.13) the QT discovery agent uses a QTimer
// that can only be shut off from the same thread it was started from.
QString devAddr = data->devName().startsWith("LE:")
? data->devName().right(data->devName().size()-3)
: data->devName();
getBtDeviceInfo(devAddr);
}
} else
// this breaks an "else if" across lines... not happy...
#endif