Fix a potential crash SimpleAudioEngineOpenSL::playEffect

Fix a crash in SimpleAudioEngineOpenSL::playEffect which would occur when OpenSLEngine::preloadEffect returned FILE_NOT_FOUND. In the case where the sound fails to preload, we should not attempt to call OpenSLEngine::setEffectLooping on that sound.
This commit is contained in:
Darragh Coy 2013-05-14 17:48:50 +01:00
parent 7f7ff26750
commit 7b67794826
1 changed files with 19 additions and 18 deletions

View File

@ -88,24 +88,25 @@ void SimpleAudioEngineOpenSL::setEffectsVolume(float volume)
unsigned int SimpleAudioEngineOpenSL::playEffect(const char* pszFilePath, bool bLoop)
{
unsigned int soundID;
do
{
soundID = s_pOpenSL->preloadEffect(pszFilePath);
if (soundID != FILE_NOT_FOUND)
{
if (s_pOpenSL->getEffectState(soundID) == PLAYSTATE_PLAYING)
{
// recreate an effect player
s_pOpenSL->recreatePlayer(pszFilePath);
break;
}
s_pOpenSL->setEffectState(soundID, PLAYSTATE_STOPPED);
s_pOpenSL->setEffectState(soundID, PLAYSTATE_PLAYING);
}
} while (0);
s_pOpenSL->setEffectLooping(soundID, bLoop);
return soundID;
unsigned int soundID = s_pOpenSL->preloadEffect(pszFilePath);
if (soundID != FILE_NOT_FOUND)
{
if (s_pOpenSL->getEffectState(soundID) == PLAYSTATE_PLAYING)
{
// recreate an effect player
s_pOpenSL->recreatePlayer(pszFilePath);
}
else
{
s_pOpenSL->setEffectState(soundID, PLAYSTATE_STOPPED);
s_pOpenSL->setEffectState(soundID, PLAYSTATE_PLAYING);
}
s_pOpenSL->setEffectLooping(soundID, bLoop);
}
return soundID;
}
void SimpleAudioEngineOpenSL::pauseEffect(unsigned int nSoundId)