From 1d2c3a42443340f8f24ef81107550bd7c5d6528f Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Fri, 23 Oct 2020 14:47:10 +0200 Subject: [PATCH] Upon clearing the file pool, clear the last used files and garbage queue I also added an early exit with an assertion to catch unintended behavior --- src/sfizz/FilePool.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index 3177018b..ff7492d6 100644 --- a/src/sfizz/FilePool.cpp +++ b/src/sfizz/FilePool.cpp @@ -435,7 +435,10 @@ void sfz::FilePool::loadingJob(QueuedFileData data) noexcept void sfz::FilePool::clear() { + std::lock_guard guard { garbageAndLastUsedMutex }; emptyFileLoadingQueues(); + garbageToCollect.clear(); + lastUsedFiles.clear(); preloadedFiles.clear(); } @@ -593,7 +596,15 @@ void sfz::FilePool::triggerGarbageCollection() noexcept if (garbageToCollect.size() == garbageToCollect.capacity()) return false; - auto& data = preloadedFiles[id]; + auto it = preloadedFiles.find(id); + if (it == preloadedFiles.end()) { + // Getting here means that the preloadedFiles got changed (probably cleared) + // while the lastUsedFiles were untouched. + ASSERTFALSE; + return true; + } + + sfz::FileData& data = it->second; if (data.status == FileData::Status::Preloaded) return true;