From bdc4269b5f5a074bb34b4d085ec24aaff8c9c347 Mon Sep 17 00:00:00 2001 From: Marek Moeckel Date: Fri, 9 May 2008 10:39:11 +0000 Subject: [PATCH] to prevent crashes on missing data, load empty wave file and throw a warning when a sound file cannot be found SVN-Revision: 5449 --- data/sounds/empty.wav | Bin 0 -> 480 bytes src/audio/sound_file.cpp | 8 ++++++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 data/sounds/empty.wav diff --git a/data/sounds/empty.wav b/data/sounds/empty.wav new file mode 100644 index 0000000000000000000000000000000000000000..36f2b7d6b2e7359547d3f50f9705af374d2646c3 GIT binary patch literal 480 zcmZutF%m#P49s;(Pw*8pn9(Yz%^00d&x4d6<2jN|a?apfvf1qIg|2OyD-aE3U(d^0 z`Q%4izb@np@u?fhC0;On1-&|8{0%ERYyRD#wZp)va(Y#qNe&8Ak$EZrQ| wD6FmNQ@lK6u1A*+BdperT<72LR;%2&C{>_6_{BdPfoq=(lf=p3mr16-0f7wSF8}}l literal 0 HcmV?d00001 diff --git a/src/audio/sound_file.cpp b/src/audio/sound_file.cpp index 2495bbbb0..98a615b14 100644 --- a/src/audio/sound_file.cpp +++ b/src/audio/sound_file.cpp @@ -398,9 +398,13 @@ SoundFile* load_sound_file(const std::string& filename) PHYSFS_file* file = PHYSFS_openRead(filename.c_str()); if(!file) { + log_warning << "Couldn't open '" << filename << "': " << PHYSFS_getLastError() << ", using dummy sound file." << std::endl; + file = PHYSFS_openRead("sounds/empty.wav"); + if (!file) { std::stringstream msg; - msg << "Couldn't open '" << filename << "': " << PHYSFS_getLastError(); - throw std::runtime_error(msg.str()); + msg << "Couldn't open dummy sound file '" << filename << "': " << PHYSFS_getLastError(); + throw std::runtime_error(msg.str()); + } } try { -- 2.11.0