Wait for texture streaming threads to finish before exiting.

This commit is contained in:
Dario 2024-07-28 22:33:52 -03:00
parent 09f7ac21d0
commit 8d6b2621f7
2 changed files with 6 additions and 3 deletions

View File

@ -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<std::thread>(&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();

View File

@ -203,7 +203,7 @@ namespace RT64 {
std::mutex uploadQueueMutex;
std::condition_variable uploadQueueChanged;
std::condition_variable uploadQueueFinished;
std::thread *uploadThread;
std::unique_ptr<std::thread> uploadThread;
std::atomic<bool> uploadThreadRunning;
std::stack<StreamDescription> streamDescStack;
std::mutex streamDescStackMutex;