From 2ea24c1a9dfdd9a2496b4636ee8757eb76a66d6a Mon Sep 17 00:00:00 2001 From: nerix Date: Wed, 3 Apr 2024 21:08:52 +0200 Subject: [PATCH] fix: use `deleteLater` for network objects and order them (#5297) --- CHANGELOG.md | 2 +- src/common/network/NetworkManager.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34c63cdb4..88793ee3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -201,7 +201,7 @@ - Dev: Refactor `StreamerMode`. (#5216, #5236) - Dev: Cleaned up unused code in `MessageElement` and `MessageLayoutElement`. (#5225) - Dev: Adapted `magic_enum` to Qt's Utf-16 strings. (#5258) -- Dev: `NetworkManager`'s statics are now created in its `init` method. (#5254) +- Dev: `NetworkManager`'s statics are now created in its `init` method. (#5254, #5297) - Dev: `clang-tidy` CI now uses Qt 6. (#5273) - Dev: Enabled `InsertNewlineAtEOF` in `clang-format`. (#5278) diff --git a/src/common/network/NetworkManager.cpp b/src/common/network/NetworkManager.cpp index 956c2e79f..eb1b7ec52 100644 --- a/src/common/network/NetworkManager.cpp +++ b/src/common/network/NetworkManager.cpp @@ -24,15 +24,19 @@ void NetworkManager::deinit() assert(NetworkManager::workerThread); assert(NetworkManager::accessManager); + // delete the access manager first: + // - put the event on the worker thread + // - wait for it to process + NetworkManager::accessManager->deleteLater(); + NetworkManager::accessManager = nullptr; + if (NetworkManager::workerThread) { NetworkManager::workerThread->quit(); NetworkManager::workerThread->wait(); } - delete NetworkManager::accessManager; - NetworkManager::accessManager = nullptr; - delete NetworkManager::workerThread; + NetworkManager::workerThread->deleteLater(); NetworkManager::workerThread = nullptr; }