From 0b030d33c87f78bf0886f0798d29b6d48cda3af0 Mon Sep 17 00:00:00 2001 From: "Yang, Ying-chao" Date: Thu, 5 Sep 2024 03:58:38 +0800 Subject: [PATCH] asyncResourceGatherer: do not detach worker threads (#477) Worker threads become non-joinable once they are detached, and `await()` will not wait for them to finish. This can lead to a crash when `asyncResourceGatherer` is destroyed in the main thread while it is still being used in worker threads. --- src/renderer/AsyncResourceGatherer.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/renderer/AsyncResourceGatherer.cpp b/src/renderer/AsyncResourceGatherer.cpp index 7cc6bba..1a77f20 100644 --- a/src/renderer/AsyncResourceGatherer.cpp +++ b/src/renderer/AsyncResourceGatherer.cpp @@ -18,10 +18,7 @@ CAsyncResourceGatherer::CAsyncResourceGatherer() { enqueueDMAFrames(); initialGatherThread = std::thread([this]() { this->gather(); }); - initialGatherThread.detach(); - - asyncLoopThread = std::thread([this]() { this->asyncAssetSpinLock(); }); - asyncLoopThread.detach(); + asyncLoopThread = std::thread([this]() { this->asyncAssetSpinLock(); }); } void CAsyncResourceGatherer::enqueueDMAFrames() {