projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix music not properly fading in again
[supertux.git]
/
src
/
audio
/
sound_file.cpp
diff --git
a/src/audio/sound_file.cpp
b/src/audio/sound_file.cpp
index
c710c3b
..
834aeda
100644
(file)
--- a/
src/audio/sound_file.cpp
+++ b/
src/audio/sound_file.cpp
@@
-32,7
+32,7
@@
#include "util/file_system.hpp"
#include "util/log.hpp"
#include "util/file_system.hpp"
#include "util/log.hpp"
-
SoundFile*
load_music_file(const std::string& filename)
+
std::unique_ptr<SoundFile>
load_music_file(const std::string& filename)
{
lisp::Parser parser(false);
const lisp::Lisp* root = parser.parse(filename);
{
lisp::Parser parser(false);
const lisp::Lisp* root = parser.parse(filename);
@@
-47,7
+47,7
@@
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);
music->get("file", raw_music_file);
music->get("loop-begin", loop_begin);
music->get("loop-at", loop_at);
-
+
if(loop_begin < 0) {
throw SoundError("can't loop from negative value");
}
if(loop_begin < 0) {
throw SoundError("can't loop from negative value");
}
@@
-62,10
+62,10
@@
SoundFile* load_music_file(const std::string& filename)
throw SoundError(msg.str());
}
throw SoundError(msg.str());
}
- return
new OggSoundFile(file, loop_begin, loop_at
);
+ return
std::unique_ptr<SoundFile>(new OggSoundFile(file, loop_begin, loop_at)
);
}
}
-
SoundFile*
load_sound_file(const std::string& filename)
+
std::unique_ptr<SoundFile>
load_sound_file(const std::string& filename)
{
if(filename.length() > 6
&& filename.compare(filename.length()-6, 6, ".music") == 0) {
{
if(filename.length() > 6
&& filename.compare(filename.length()-6, 6, ".music") == 0) {
@@
-83,11
+83,16
@@
SoundFile* load_sound_file(const std::string& filename)
char magic[4];
if(PHYSFS_read(file, magic, sizeof(magic), 1) != 1)
throw SoundError("Couldn't read magic, file too short");
char magic[4];
if(PHYSFS_read(file, magic, sizeof(magic), 1) != 1)
throw SoundError("Couldn't read magic, file too short");
- PHYSFS_seek(file, 0);
+ if (PHYSFS_seek(file, 0) == 0) {
+ std::stringstream msg;
+ msg << "Couldn't seek through sound file: " << PHYSFS_getLastError();
+ throw SoundError(msg.str());
+ }
+
if(strncmp(magic, "RIFF", 4) == 0)
if(strncmp(magic, "RIFF", 4) == 0)
- return
new WavSoundFile(file
);
+ return
std::unique_ptr<SoundFile>(new WavSoundFile(file)
);
else if(strncmp(magic, "OggS", 4) == 0)
else if(strncmp(magic, "OggS", 4) == 0)
- return
new OggSoundFile(file, 0, -1
);
+ return
std::unique_ptr<SoundFile>(new OggSoundFile(file, 0, -1)
);
else
throw SoundError("Unknown file format");
} catch(std::exception& e) {
else
throw SoundError("Unknown file format");
} catch(std::exception& e) {