From e028fdced9c50fc95075ac6b578d6f720ee3cb5a Mon Sep 17 00:00:00 2001 From: paulfd Date: Mon, 16 Sep 2019 15:11:15 +0200 Subject: [PATCH] Corrected a bug when reloading files, where the string views used for the FilePool hash table where pointing towards freed memory. --- sfizz/FilePool.cpp | 8 ++++++++ sfizz/FilePool.h | 1 + sfizz/Synth.cpp | 1 + 3 files changed, 10 insertions(+) diff --git a/sfizz/FilePool.cpp b/sfizz/FilePool.cpp index 18aedad6..9c1b9447 100644 --- a/sfizz/FilePool.cpp +++ b/sfizz/FilePool.cpp @@ -120,4 +120,12 @@ void sfz::FilePool::loadingThread() noexcept auto fileLoaded = std::make_unique>(sndFile.channels(), fileToLoad.numFrames); fileToLoad.voice->setFileData(readFromFile(sndFile, fileToLoad.numFrames), fileToLoad.ticket); } +} + +void sfz::FilePool::clear() +{ + preloadedData.clear(); + while(loadingQueue.pop()){ + // Pop the queue + } } \ No newline at end of file diff --git a/sfizz/FilePool.h b/sfizz/FilePool.h index 31e31fb8..77d650d7 100644 --- a/sfizz/FilePool.h +++ b/sfizz/FilePool.h @@ -59,6 +59,7 @@ public: }; std::optional getFileInformation(std::string_view filename, uint32_t offset) noexcept; void enqueueLoading(Voice* voice, std::string_view sample, int numFrames, unsigned ticket) noexcept; + void clear(); private: std::filesystem::path rootDirectory; struct FileLoadingInformation { diff --git a/sfizz/Synth.cpp b/sfizz/Synth.cpp index 86166454..13b72566 100644 --- a/sfizz/Synth.cpp +++ b/sfizz/Synth.cpp @@ -119,6 +119,7 @@ void sfz::Synth::clear() masterOpcodes.clear(); groupOpcodes.clear(); regions.clear(); + filePool.clear(); } void sfz::Synth::handleGlobalOpcodes(const std::vector& members)