#303: Typo fixes from mathnerd314
[supertux.git] / src / audio / sound_file.cpp
index a9e61e7..6352110 100644 (file)
@@ -128,7 +128,7 @@ WavSoundFile::WavSoundFile(PHYSFS_file* file)
 
   if(chunklen > 16) {
     if(PHYSFS_seek(file, PHYSFS_tell(file) + (chunklen-16)) == 0)
-      throw std::runtime_error("EOF while reading reast of format chunk");
+      throw std::runtime_error("EOF while reading rest of format chunk");
   }
 
   // set file offset to DATA chunk data
@@ -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) {