aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorThierry Crozat2011-06-26 18:40:31 +0100
committerThierry Crozat2011-06-26 18:40:31 +0100
commit55a7bbf86abce9bd44b11fceed7e2a6a8bc49b51 (patch)
treee25340279240c4f712999f09814c9cbaa20d8703 /engines
parent32392c9430c80d323914ffa91d4f08272396dcd9 (diff)
downloadscummvm-rg350-55a7bbf86abce9bd44b11fceed7e2a6a8bc49b51.tar.gz
scummvm-rg350-55a7bbf86abce9bd44b11fceed7e2a6a8bc49b51.tar.bz2
scummvm-rg350-55a7bbf86abce9bd44b11fceed7e2a6a8bc49b51.zip
SWORD25: Change unknow handle error into a warning
Also add sanity checks when calling findHandle() in the SoundEngine. This fixes an issue when functions of SoundEngine are called on a sound that has already finished playing (the most common occurrences are calls to isSoundPlaying()).
Diffstat (limited to 'engines')
-rw-r--r--engines/sword25/sfx/soundengine.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/engines/sword25/sfx/soundengine.cpp b/engines/sword25/sfx/soundengine.cpp
index 130383f8ef..7c8a6593aa 100644
--- a/engines/sword25/sfx/soundengine.cpp
+++ b/engines/sword25/sfx/soundengine.cpp
@@ -174,7 +174,7 @@ SndHandle *SoundEngine::findHandle(uint id) {
return &_handles[i];
}
- error("Sound::findHandle(): Unknown handle");
+ warning("Sound::findHandle(): Unknown handle");
return NULL;
}
@@ -224,31 +224,41 @@ uint SoundEngine::playSoundEx(const Common::String &fileName, SOUND_TYPES type,
void SoundEngine::setSoundVolume(uint handle, float volume) {
debugC(1, kDebugSound, "SoundEngine::setSoundVolume(%d, %f)", handle, volume);
- _mixer->setChannelVolume(findHandle(handle)->handle, (byte)(volume * 255));
+ SndHandle* sndHandle = findHandle(handle);
+ if (sndHandle != NULL)
+ _mixer->setChannelVolume(sndHandle->handle, (byte)(volume * 255));
}
void SoundEngine::setSoundPanning(uint handle, float pan) {
debugC(1, kDebugSound, "SoundEngine::setSoundPanning(%d, %f)", handle, pan);
- _mixer->setChannelBalance(findHandle(handle)->handle, (int8)(pan * 127));
+ SndHandle* sndHandle = findHandle(handle);
+ if (sndHandle != NULL)
+ _mixer->setChannelBalance(sndHandle->handle, (int8)(pan * 127));
}
void SoundEngine::pauseSound(uint handle) {
debugC(1, kDebugSound, "SoundEngine::pauseSound(%d)", handle);
- _mixer->pauseHandle(findHandle(handle)->handle, true);
+ SndHandle* sndHandle = findHandle(handle);
+ if (sndHandle != NULL)
+ _mixer->pauseHandle(sndHandle->handle, true);
}
void SoundEngine::resumeSound(uint handle) {
debugC(1, kDebugSound, "SoundEngine::resumeSound(%d)", handle);
- _mixer->pauseHandle(findHandle(handle)->handle, false);
+ SndHandle* sndHandle = findHandle(handle);
+ if (sndHandle != NULL)
+ _mixer->pauseHandle(sndHandle->handle, false);
}
void SoundEngine::stopSound(uint handle) {
debugC(1, kDebugSound, "SoundEngine::stopSound(%d)", handle);
- _mixer->stopHandle(findHandle(handle)->handle);
+ SndHandle* sndHandle = findHandle(handle);
+ if (sndHandle != NULL)
+ _mixer->stopHandle(sndHandle->handle);
}
bool SoundEngine::isSoundPaused(uint handle) {
@@ -262,19 +272,28 @@ bool SoundEngine::isSoundPaused(uint handle) {
bool SoundEngine::isSoundPlaying(uint handle) {
debugC(1, kDebugSound, "SoundEngine::isSoundPlaying(%d)", handle);
- return _mixer->isSoundHandleActive(findHandle(handle)->handle);
+ SndHandle* sndHandle = findHandle(handle);
+ if (sndHandle == NULL)
+ return false;
+ return _mixer->isSoundHandleActive(sndHandle->handle);
}
float SoundEngine::getSoundVolume(uint handle) {
debugC(1, kDebugSound, "SoundEngine::getSoundVolume(%d)", handle);
- return (float)_mixer->getChannelVolume(findHandle(handle)->handle) / 255.0;
+ SndHandle* sndHandle = findHandle(handle);
+ if (sndHandle == NULL)
+ return 0.f;
+ return (float)_mixer->getChannelVolume(sndHandle->handle) / 255.0;
}
float SoundEngine::getSoundPanning(uint handle) {
debugC(1, kDebugSound, "SoundEngine::getSoundPanning(%d)", handle);
- return (float)_mixer->getChannelBalance(findHandle(handle)->handle) / 127.0;
+ SndHandle* sndHandle = findHandle(handle);
+ if (sndHandle == NULL)
+ return 0.f;
+ return (float)_mixer->getChannelBalance(sndHandle->handle) / 127.0;
}
Resource *SoundEngine::loadResource(const Common::String &fileName) {