aboutsummaryrefslogtreecommitdiff
path: root/engines/sword2/music.cpp
diff options
context:
space:
mode:
authorTorbjörn Andersson2008-07-18 04:16:00 +0000
committerTorbjörn Andersson2008-07-18 04:16:00 +0000
commit702e26965c48e99490c25ca635e41c14ac88add2 (patch)
tree132daf046e54c4cd1d244b1d3be8b9f21be7cf05 /engines/sword2/music.cpp
parent0f74124d789488d42bc62b6a8bcf67d31e0b9bfd (diff)
downloadscummvm-rg350-702e26965c48e99490c25ca635e41c14ac88add2.tar.gz
scummvm-rg350-702e26965c48e99490c25ca635e41c14ac88add2.tar.bz2
scummvm-rg350-702e26965c48e99490c25ca635e41c14ac88add2.zip
Don't crash if you try to use music file #2 as music file #1. When the music
wasn't found, it would close the file even if something else was already playing from it. (Some music is in both files.) svn-id: r33094
Diffstat (limited to 'engines/sword2/music.cpp')
-rw-r--r--engines/sword2/music.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/engines/sword2/music.cpp b/engines/sword2/music.cpp
index fd72ba8d52..3b5a09578b 100644
--- a/engines/sword2/music.cpp
+++ b/engines/sword2/music.cpp
@@ -52,9 +52,11 @@ namespace Sword2 {
static Audio::AudioStream *makeCLUStream(Common::File *fp, int size);
static Audio::AudioStream *getAudioStream(SoundFileHandle *fh, const char *base, int cd, uint32 id, uint32 *numSamples) {
- debug(3, "Playing %s from CD %d", base, cd);
+ bool alreadyOpen;
if (!fh->file.isOpen()) {
+ alreadyOpen = false;
+
struct {
const char *ext;
int mode;
@@ -75,16 +77,14 @@ static Audio::AudioStream *getAudioStream(SoundFileHandle *fh, const char *base,
char filename[20];
for (int i = 0; i < ARRAYSIZE(file_types); i++) {
- Common::File f;
-
sprintf(filename, "%s%d.%s", base, cd, file_types[i].ext);
- if (f.open(filename)) {
+ if (Common::File::exists(filename)) {
soundMode = file_types[i].mode;
break;
}
sprintf(filename, "%s.%s", base, file_types[i].ext);
- if (f.open(filename)) {
+ if (Common::File::exists(filename)) {
soundMode = file_types[i].mode;
break;
}
@@ -105,7 +105,8 @@ static Audio::AudioStream *getAudioStream(SoundFileHandle *fh, const char *base,
fh->idxTab = NULL;
}
}
- }
+ } else
+ alreadyOpen = true;
uint32 entrySize = (fh->fileType == kCLUMode) ? 2 : 3;
@@ -134,7 +135,13 @@ static Audio::AudioStream *getAudioStream(SoundFileHandle *fh, const char *base,
*numSamples = len;
if (!pos || !len) {
- fh->file.close();
+ // We couldn't find the sound. Possibly as a result of a bad
+ // installation (e.g. using the music file from CD 2 as the
+ // first music file). Don't close the file if it was already
+ // open though, because something is playing from it.
+ warning("getAudioStream: Could not find %s ID %d! Possibly the wrong file", base, id);
+ if (!alreadyOpen)
+ fh->file.close();
return NULL;
}