From 8d6b2621f778e367c6333fc94a7a561a7407e3fb Mon Sep 17 00:00:00 2001 From: Dario Date: Sun, 28 Jul 2024 22:33:52 -0300 Subject: [PATCH] Wait for texture streaming threads to finish before exiting. --- src/render/rt64_texture_cache.cpp | 7 +++++-- src/render/rt64_texture_cache.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/render/rt64_texture_cache.cpp b/src/render/rt64_texture_cache.cpp index 0a0d099..3615387 100644 --- a/src/render/rt64_texture_cache.cpp +++ b/src/render/rt64_texture_cache.cpp @@ -471,7 +471,7 @@ namespace RT64 { uploadResourcePool = directWorker->device->createPool(poolDesc); // Create upload thread. - uploadThread = new std::thread(&TextureCache::uploadThreadLoop, this); + uploadThread = std::make_unique(&TextureCache::uploadThreadLoop, this); // Create streaming threads. streamDescStackActiveCount = threadCount; @@ -482,11 +482,14 @@ namespace RT64 { } TextureCache::~TextureCache() { + waitForAllStreamThreads(true); + streamThreads.clear(); + if (uploadThread != nullptr) { uploadThreadRunning = false; uploadQueueChanged.notify_all(); uploadThread->join(); - delete uploadThread; + uploadThread.reset(); } descriptorSets.clear(); diff --git a/src/render/rt64_texture_cache.h b/src/render/rt64_texture_cache.h index 118421d..2c7919e 100644 --- a/src/render/rt64_texture_cache.h +++ b/src/render/rt64_texture_cache.h @@ -203,7 +203,7 @@ namespace RT64 { std::mutex uploadQueueMutex; std::condition_variable uploadQueueChanged; std::condition_variable uploadQueueFinished; - std::thread *uploadThread; + std::unique_ptr uploadThread; std::atomic uploadThreadRunning; std::stack streamDescStack; std::mutex streamDescStackMutex;