CPath::lookup is not thread-safe

develop
kaetemi 5 years ago
parent 900ec1a69a
commit a82df91bba

@ -96,6 +96,8 @@ private:
IAudioDecoder *m_AudioDecoder; IAudioDecoder *m_AudioDecoder;
std::string m_LookupPath;
bool m_Paused; bool m_Paused;
bool m_DecodingEnded; bool m_DecodingEnded;

@ -56,18 +56,12 @@ IAudioDecoder::~IAudioDecoder()
IAudioDecoder *IAudioDecoder::createAudioDecoder(const std::string &filepath, bool async, bool loop) 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); std::string type = CFile::getExtension(filepath);
CIFile *ifile = new CIFile(); CIFile *ifile = new CIFile();
ifile->setCacheFileOnOpen(!async); ifile->setCacheFileOnOpen(!async);
ifile->allowBNPCacheFileOnOpen(!async); ifile->allowBNPCacheFileOnOpen(!async);
ifile->open(lookup); ifile->open(filepath);
IAudioDecoder *mb = createAudioDecoder(type, ifile, loop); IAudioDecoder *mb = createAudioDecoder(type, ifile, loop);

@ -108,6 +108,13 @@ void CStreamFileSource::play()
//{ //{
// nlwarning("Already waiting for 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 (!getStreamFileSound()->getAsync())
{ {
if (!prepareDecoder()) if (!prepareDecoder())
@ -272,7 +279,8 @@ bool CStreamFileSource::prepareDecoder()
if (!m_AudioDecoder) if (!m_AudioDecoder)
{ {
// load the file // 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) if (!m_AudioDecoder)
{ {
nlwarning("Failed to create IAudioDecoder, likely invalid format"); nlwarning("Failed to create IAudioDecoder, likely invalid format");

Loading…
Cancel
Save