1
0
forked from 0ad/0ad

vfs: disable error dialog if file not found

SoundGroup.cpp: add proper error reporting if snd_open fails

This was SVN commit r7493.
This commit is contained in:
janwas 2010-05-01 18:36:24 +00:00
parent e140aa7baf
commit 9864da20fc
3 changed files with 25 additions and 7 deletions

View File

@ -58,7 +58,7 @@ LibError Open(const fs::wpath& pathname, wchar_t mode, int& fd)
#endif
fd = wopen(pathname.string().c_str(), oflag, S_IRWXO|S_IRWXU|S_IRWXG);
if(fd < 0)
WARN_RETURN(ERR::FILE_ACCESS);
return LibError_from_errno();
stats_open();
return INFO::OK;

View File

@ -130,7 +130,11 @@ public:
if(!isCacheHit)
{
VfsDirectory* directory; VfsFile* file;
CHECK_ERR(vfs_Lookup(pathname, &m_rootDirectory, directory, &file));
// per 2010-05-01 meeting, this shouldn't raise 'scary error
// dialogs', which often fail to display the culprit pathname
// (debug_DumpStack doesn't correctly analyze fs::[w]path).
// instead, callers should log the error, including pathname.
RETURN_ERR(vfs_Lookup(pathname, &m_rootDirectory, directory, &file));
size = file->Size();
// safely handle zero-length files

View File

@ -115,6 +115,13 @@ void CSoundGroup::UploadPropertiesAndPlay(Handle hSound, const CVector3D& positi
}
static void HandleError(const std::wstring& message, const VfsPath& pathname, LibError err)
{
if(err == ERR::AGAIN)
return; // open failed because sound is disabled (don't log this)
LOG(CLogger::Error, LOG_CATEGORY, L"%ws: pathname=%ws, error=%ld", message.c_str(), pathname.string().c_str(), err);
}
void CSoundGroup::PlayNext(const CVector3D& position)
{
if(m_Intensity >= m_IntensityThreshold)
@ -122,10 +129,14 @@ void CSoundGroup::PlayNext(const CVector3D& position)
if(!is_playing(m_hReplacement))
{
// load up replacement file
m_hReplacement = snd_open(m_filepath/m_intensity_file);
if(m_hReplacement < 0) // one cause: sound is disabled
const VfsPath pathname(m_filepath/m_intensity_file);
m_hReplacement = snd_open(pathname);
if(m_hReplacement < 0)
{
HandleError(L"PlayNext: snd_open for replacement file failed", pathname, (LibError)m_hReplacement);
return;
}
UploadPropertiesAndPlay(m_hReplacement, position);
}
}
@ -139,9 +150,12 @@ void CSoundGroup::PlayNext(const CVector3D& position)
if(TestFlag(eRandOrder))
m_index = (size_t)rand(0, (size_t)filenames.size());
// (note: previously snd_group[m_index] was used in place of hs)
Handle hs = snd_open(m_filepath/filenames[m_index]);
if(hs < 0) // one cause: sound is disabled
const VfsPath pathname(m_filepath/filenames[m_index]);
Handle hs = snd_open(pathname);
{
HandleError(L"PlayNext: snd_open failed", pathname, (LibError)m_hReplacement);
return;
}
UploadPropertiesAndPlay(hs, position);
}