diff --git a/source/soundmanager/js/SoundGroup.cpp b/source/soundmanager/js/SoundGroup.cpp index 1188583baf..76865bea26 100644 --- a/source/soundmanager/js/SoundGroup.cpp +++ b/source/soundmanager/js/SoundGroup.cpp @@ -160,7 +160,8 @@ float CSoundGroup::RadiansOffCenter(const CVector3D& position, bool& onScreen, f void CSoundGroup::UploadPropertiesAndPlay(int theIndex, const CVector3D& position) { #if CONFIG2_AUDIO - if ( g_SoundManager ) { + if ( g_SoundManager ) + { bool isOnscreen; ALfloat initialRolllOff = 0.1f; ALfloat itemRollOff = initialRolllOff; @@ -172,31 +173,36 @@ void CSoundGroup::UploadPropertiesAndPlay(int theIndex, const CVector3D& positio if (snd_group.size() == 0) Reload(); - ISoundItem* hSound = snd_group[theIndex]; - CVector3D origin = g_Game->GetView()->GetCamera()->GetOrientation().GetTranslation(); - float sndDist = origin.Y; - - if (!TestFlag(eOmnipresent)) + if ( snd_group.size() > theIndex ) { - if (TestFlag(eDistanceless)) - itemRollOff = 0; - - hSound->SetLocation(CVector3D((sndDist * sin(offSet)), 0, - sndDist * cos(offSet))); - hSound->SetRollOff(itemRollOff); + if ( ISoundItem* hSound = snd_group[theIndex] ) + { + CVector3D origin = g_Game->GetView()->GetCamera()->GetOrientation().GetTranslation(); + float sndDist = origin.Y; + + if (!TestFlag(eOmnipresent)) + { + if (TestFlag(eDistanceless)) + itemRollOff = 0; + + hSound->SetLocation(CVector3D((sndDist * sin(offSet)), 0, - sndDist * cos(offSet))); + hSound->SetRollOff(itemRollOff); + } + + if (TestFlag(eRandPitch)) + hSound->SetPitch(RandFloat(m_PitchLower, m_PitchUpper)); + else + hSound->SetPitch(m_Pitch); + + ALfloat theGain = m_Gain; + if (TestFlag(eRandGain)) + theGain = RandFloat(m_GainLower, m_GainUpper); + + hSound->SetCone(m_ConeInnerAngle, m_ConeOuterAngle, m_ConeOuterGain); + + g_SoundManager->PlayGroupItem(hSound, theGain); + } } - - if (TestFlag(eRandPitch)) - hSound->SetPitch(RandFloat(m_PitchLower, m_PitchUpper)); - else - hSound->SetPitch(m_Pitch); - - ALfloat theGain = m_Gain; - if (TestFlag(eRandGain)) - theGain = RandFloat(m_GainLower, m_GainUpper); - - hSound->SetCone(m_ConeInnerAngle, m_ConeOuterAngle, m_ConeOuterGain); - - g_SoundManager->PlayGroupItem(hSound, theGain); } } #else // !CONFIG2_AUDIO