X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Faudio%2Fsound_file.cpp;h=98a615b148aa3941c9c69f703765d2cac696fde1;hb=6b0c80bde84af0bf9323320d99f2fccd7c9eeedd;hp=a9e61e7486f0ddc258418724527e74f3a3895186;hpb=87ad4c5713c0cbf1c71f16ec97bedcb315cb14c3;p=supertux.git diff --git a/src/audio/sound_file.cpp b/src/audio/sound_file.cpp index a9e61e748..98a615b14 100644 --- a/src/audio/sound_file.cpp +++ b/src/audio/sound_file.cpp @@ -272,7 +272,7 @@ OggSoundFile::read(void* _buffer, size_t buffer_size) if(bytes_left_till_loop <= 4) break; - if(bytes_left_till_loop < bytes_to_read) { + if(bytes_left_till_loop < (ogg_int64_t) bytes_to_read) { bytes_to_read = (size_t) bytes_left_till_loop; } } @@ -371,6 +371,10 @@ SoundFile* load_music_file(const std::string& filename) music->get("file", raw_music_file); music->get("loop-begin", loop_begin); music->get("loop-at", loop_at); + + if(loop_begin < 0) { + throw std::runtime_error("can't loop from negative value"); + } std::string basedir = FileSystem::dirname(filename); raw_music_file = FileSystem::normalize(basedir + raw_music_file); @@ -394,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 { @@ -407,7 +415,7 @@ SoundFile* load_sound_file(const std::string& filename) if(strncmp(magic, "RIFF", 4) == 0) return new WavSoundFile(file); else if(strncmp(magic, "OggS", 4) == 0) - return new OggSoundFile(file, -1, 0); + return new OggSoundFile(file, 0, -1); else throw std::runtime_error("Unknown file format"); } catch(std::exception& e) {