From 4a26785eda43c42879d5758c5e1110d6005cf46e Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 24 Apr 2017 18:21:27 -0400 Subject: [PATCH] cleanup Audio bg threads in cleanupBeforeQuit --- interface/src/Application.cpp | 3 ++- libraries/audio-client/src/AudioClient.cpp | 21 +++++++++++++++------ libraries/audio-client/src/AudioClient.h | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c94b1bbd2f..ff6f85c8b2 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1785,7 +1785,8 @@ void Application::cleanupBeforeQuit() { // FIXME: something else is holding a reference to AudioClient, // so it must be explicitly synchronously stopped here - QMetaObject::invokeMethod(DependencyManager::get().data(), "stop", Qt::BlockingQueuedConnection); + QMetaObject::invokeMethod(DependencyManager::get().data(), + "cleanupBeforeQuit", Qt::BlockingQueuedConnection); // destroy Audio so it and its threads have a chance to go down safely // this must happen after QML, as there are unexplained audio crashes originating in qtwebengine diff --git a/libraries/audio-client/src/AudioClient.cpp b/libraries/audio-client/src/AudioClient.cpp index 6107fef516..fbb578f560 100644 --- a/libraries/audio-client/src/AudioClient.cpp +++ b/libraries/audio-client/src/AudioClient.cpp @@ -254,15 +254,24 @@ AudioClient::~AudioClient() { } void AudioClient::customDeleter() { - stop(); // synchronously + deleteLater(); +} - static_cast(_checkDevicesThread)->join(); - delete _checkDevicesThread; +void AudioClient::cleanupBeforeQuit() { + // FIXME: this should be put in customDeleter, but there is still a reference to this when it is called, + // so this must be explicitly, synchronously stopped - static_cast(_localInjectorsThread)->join(); - delete _localInjectorsThread; + stop(); - deleteLater(); // asynchronously + if (_checkDevicesThread) { + static_cast(_checkDevicesThread)->join(); + delete _checkDevicesThread; + } + + if (_localInjectorsThread) { + static_cast(_localInjectorsThread)->join(); + delete _localInjectorsThread; + } } void AudioClient::handleMismatchAudioFormat(SharedNodePointer node, const QString& currentCodec, const QString& recievedCodec) { diff --git a/libraries/audio-client/src/AudioClient.h b/libraries/audio-client/src/AudioClient.h index 6e69915f0a..f3038b4d62 100644 --- a/libraries/audio-client/src/AudioClient.h +++ b/libraries/audio-client/src/AudioClient.h @@ -158,6 +158,7 @@ public: public slots: void start(); void stop(); + void cleanupBeforeQuit(); void handleAudioEnvironmentDataPacket(QSharedPointer message); void handleAudioDataPacket(QSharedPointer message);