From aacb664bffc2baa47c6f6a8ec9a224149fd06977 Mon Sep 17 00:00:00 2001 From: Benoit Maurin Date: Thu, 21 Nov 2024 22:47:29 +0100 Subject: [PATCH] Bugfix for racy crash on opening bad serial port Signed-off-by: Benoit Maurin --- src/Comms/SerialLink.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Comms/SerialLink.cc b/src/Comms/SerialLink.cc index f293945c511..62ff2978e6d 100644 --- a/src/Comms/SerialLink.cc +++ b/src/Comms/SerialLink.cc @@ -171,8 +171,6 @@ bool SerialLink::_hardwareConnect(QSerialPort::SerialPortError& error, QString& _port = new QSerialPort(_serialConfig->portName(), this); - QObject::connect(_port, &QSerialPort::errorOccurred, this, &SerialLink::linkError); - QObject::connect(_port, &QIODevice::readyRead, this, &SerialLink::_readBytes); // After the bootloader times out, it still can take a second or so for the Pixhawk USB driver to come up and make // the port available for open. So we retry a few times to wait for it. @@ -216,6 +214,9 @@ bool SerialLink::_hardwareConnect(QSerialPort::SerialPortError& error, QString& emit connected(); + QObject::connect(_port, &QSerialPort::errorOccurred, this, &SerialLink::linkError); + QObject::connect(_port, &QIODevice::readyRead, this, &SerialLink::_readBytes); + qCDebug(SerialLinkLog) << "Connection SeriaLink: " << "with settings" << _serialConfig->portName() << _serialConfig->baud() << _serialConfig->dataBits() << _serialConfig->parity() << _serialConfig->stopBits();