From a82df91bba52642d7c221e6aa0fb031bb155cf18 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Thu, 9 Apr 2020 13:02:50 +0800 Subject: [PATCH] CPath::lookup is not thread-safe --- nel/include/nel/sound/stream_file_source.h | 2 ++ nel/src/sound/audio_decoder.cpp | 8 +------- nel/src/sound/stream_file_source.cpp | 10 +++++++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/nel/include/nel/sound/stream_file_source.h b/nel/include/nel/sound/stream_file_source.h index 4069a2f58..c8cf91cf5 100644 --- a/nel/include/nel/sound/stream_file_source.h +++ b/nel/include/nel/sound/stream_file_source.h @@ -96,6 +96,8 @@ private: IAudioDecoder *m_AudioDecoder; + std::string m_LookupPath; + bool m_Paused; bool m_DecodingEnded; diff --git a/nel/src/sound/audio_decoder.cpp b/nel/src/sound/audio_decoder.cpp index ac7745721..a282942c4 100644 --- a/nel/src/sound/audio_decoder.cpp +++ b/nel/src/sound/audio_decoder.cpp @@ -56,18 +56,12 @@ IAudioDecoder::~IAudioDecoder() IAudioDecoder *IAudioDecoder::createAudioDecoder(const std::string &filepath, bool async, bool loop) { - std::string lookup = CPath::lookup(filepath, false); - if (lookup.empty()) - { - nlwarning("Music file %s does not exist!", filepath.c_str()); - return NULL; - } std::string type = CFile::getExtension(filepath); CIFile *ifile = new CIFile(); ifile->setCacheFileOnOpen(!async); ifile->allowBNPCacheFileOnOpen(!async); - ifile->open(lookup); + ifile->open(filepath); IAudioDecoder *mb = createAudioDecoder(type, ifile, loop); diff --git a/nel/src/sound/stream_file_source.cpp b/nel/src/sound/stream_file_source.cpp index fbd720a89..50d9bda97 100644 --- a/nel/src/sound/stream_file_source.cpp +++ b/nel/src/sound/stream_file_source.cpp @@ -108,6 +108,13 @@ void CStreamFileSource::play() //{ // nlwarning("Already waiting for play"); //} + std::string filepath = getStreamFileSound()->getFilePath(); + m_LookupPath = NLMISC::CPath::lookup(filepath, false, false); + if (m_LookupPath.empty()) + { + nlwarning("Music file %s does not exist!", filepath.c_str()); + return; + } if (!getStreamFileSound()->getAsync()) { if (!prepareDecoder()) @@ -272,7 +279,8 @@ bool CStreamFileSource::prepareDecoder() if (!m_AudioDecoder) { // load the file - m_AudioDecoder = IAudioDecoder::createAudioDecoder(getStreamFileSound()->getFilePath(), getStreamFileSound()->getAsync(), getStreamFileSound()->getLooping()); + nlassert(!m_LookupPath.empty()); + m_AudioDecoder = IAudioDecoder::createAudioDecoder(m_LookupPath, getStreamFileSound()->getAsync(), getStreamFileSound()->getLooping()); if (!m_AudioDecoder) { nlwarning("Failed to create IAudioDecoder, likely invalid format");