Skip to content

Commit ccf952b

Browse files
committed
SerialLink: Fix Crash on Cleanup
1 parent bd237db commit ccf952b

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/Comms/SerialLink.cc

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
#include "SerialLink.h"
1111
#include "QGCLoggingCategory.h"
1212
#include "QGCSerialPortInfo.h"
13-
#ifdef Q_OS_ANDROID
14-
#include "qserialportinfo.h"
15-
#else
16-
#include <QtSerialPort/QSerialPortInfo>
17-
#endif
1813
#include <QtCore/QSettings>
1914
#include <QtCore/QThread>
2015
#include <QtCore/QTimer>
@@ -32,20 +27,20 @@ namespace {
3227
SerialConfiguration::SerialConfiguration(const QString &name, QObject *parent)
3328
: LinkConfiguration(name, parent)
3429
{
35-
// qCDebug(SerialLinkLog) << Q_FUNC_INFO << this;
30+
// qCDebug(SerialLinkLog) << this;
3631
}
3732

3833
SerialConfiguration::SerialConfiguration(const SerialConfiguration *source, QObject *parent)
3934
: LinkConfiguration(source, parent)
4035
{
41-
// qCDebug(SerialLinkLog) << Q_FUNC_INFO << this;
36+
// qCDebug(SerialLinkLog) << this;
4237

4338
SerialConfiguration::copyFrom(source);
4439
}
4540

4641
SerialConfiguration::~SerialConfiguration()
4742
{
48-
// qCDebug(SerialLinkLog) << Q_FUNC_INFO << this;
43+
// qCDebug(SerialLinkLog) << this;
4944
}
5045

5146
void SerialConfiguration::setPortName(const QString &name)
@@ -142,7 +137,7 @@ SerialWorker::SerialWorker(const SerialConfiguration *config, QObject *parent)
142137
: QObject(parent)
143138
, _serialConfig(config)
144139
{
145-
// qCDebug(SerialLinkLog) << Q_FUNC_INFO << this;
140+
// qCDebug(SerialLinkLog) << this;
146141

147142
(void) qRegisterMetaType<QSerialPort::SerialPortError>("QSerialPort::SerialPortError");
148143
}
@@ -151,7 +146,7 @@ SerialWorker::~SerialWorker()
151146
{
152147
disconnectFromPort();
153148

154-
// qCDebug(SerialLinkLog) << Q_FUNC_INFO << this;
149+
// qCDebug(SerialLinkLog) << this;
155150
}
156151

157152
bool SerialWorker::isConnected() const
@@ -289,7 +284,7 @@ void SerialWorker::_onPortReadyRead()
289284
{
290285
const QByteArray data = _port->readAll();
291286
if (!data.isEmpty()) {
292-
// qCDebug(SerialLinkLog) << "_onPortReadyRead:" << data.size();
287+
// qCDebug(SerialLinkLog) << data.size();
293288
emit dataReceived(data);
294289
}
295290
}
@@ -354,11 +349,11 @@ SerialLink::SerialLink(SharedLinkConfigurationPtr &config, QObject *parent)
354349
, _worker(new SerialWorker(_serialConfig))
355350
, _workerThread(new QThread(this))
356351
{
357-
// qCDebug(SerialLinkLog) << Q_FUNC_INFO << this;
352+
// qCDebug(SerialLinkLog) << this;
358353

359354
_workerThread->setObjectName(QStringLiteral("Serial_%1").arg(_serialConfig->name()));
360355

361-
_worker->moveToThread(_workerThread);
356+
(void) _worker->moveToThread(_workerThread);
362357

363358
(void) connect(_workerThread, &QThread::started, _worker, &SerialWorker::setupPort);
364359
(void) connect(_workerThread, &QThread::finished, _worker, &QObject::deleteLater);
@@ -374,15 +369,14 @@ SerialLink::SerialLink(SharedLinkConfigurationPtr &config, QObject *parent)
374369

375370
SerialLink::~SerialLink()
376371
{
377-
SerialLink::disconnect();
372+
(void) QMetaObject::invokeMethod(_worker, "disconnectFromPort", Qt::BlockingQueuedConnection);
378373

379374
_workerThread->quit();
380375
if (!_workerThread->wait(DISCONNECT_TIMEOUT_MS)) {
381376
qCWarning(SerialLinkLog) << "Failed to wait for Serial Thread to close";
382-
// _workerThread->terminate();
383377
}
384378

385-
// qCDebug(SerialLinkLog) << Q_FUNC_INFO << this;
379+
// qCDebug(SerialLinkLog) << this;
386380
}
387381

388382
bool SerialLink::isConnected() const

src/Utilities/QGCLogging.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
#include "SettingsManager.h"
1515

1616
#include <QtConcurrent/QtConcurrentRun>
17-
#include <QtCore/qapplicationstatic.h>
17+
#include <QtCore/QGlobalStatic>
1818
#include <QtCore/QStringListModel>
1919
#include <QtCore/QTextStream>
2020

2121
QGC_LOGGING_CATEGORY(QGCLoggingLog, "QGCLoggingLog")
2222

23-
Q_APPLICATION_STATIC(QGCLogging, _qgcLogging)
23+
Q_GLOBAL_STATIC(QGCLogging, _qgcLogging)
2424

2525
static QtMessageHandler defaultHandler = nullptr;
2626

@@ -82,7 +82,7 @@ void QGCLogging::log(const QString &message)
8282
{
8383
// Emit the signal so threadsafeLog runs in the correct thread
8484
if (!_ioError) {
85-
emit _qgcLogging->emitLog(message);
85+
emit emitLog(message);
8686
}
8787
}
8888

0 commit comments

Comments
 (0)