Reputation: 5897
I have myself a SoundLoader class which loads some wav files into a map of soundbuffers and then I can call a method called PlaySound which takes an enum to play the sound, here is my method
void SoundLoader::PlaySound(SoundNames soundName)
{
if (playingSounds.size() == 0)
{
playingSounds.push_back(sf::Sound());
playingSounds.at(0).setBuffer(Sounds[soundName]);
playingSounds.at(0).play();
}
else
{
int location = -1;
for (int i = 0; i < playingSounds.size(); i++)
{
if (!playingSounds.at(i).getStatus() == sf::Sound::Playing && location != -1)
{
location = i;
}
}
if (location != -1)
{
playingSounds.at(location).setBuffer(Sounds[soundName]);
playingSounds.at(location).play();
}
else
{
playingSounds.push_back(sf::Sound());
playingSounds.at(playingSounds.size()-1).setBuffer(Sounds[soundName]);
playingSounds.at(playingSounds.size() - 1).play();
}
}
}
However I was testing my game and for a minute or so it is all going fine, but then all of a sudden I got this error
An internal OpenAL call failed in SoundSource.cpp (181) : AL_INVALID_NAME, an unacceptable name has been specified
What am I doing to cause this? P.S. my soundloader only has 60 lines of code so not sure what the 181 is relating to
Upvotes: 0
Views: 1001
Reputation: 5897
Its ok I found out my error
if (playingSounds.at(i).getStatus() != sf::Sound::Playing && location == -1)
{
location = i;
}
Just to help any other person that has this problem, make sure you never have more than 140 sf::Sounds in memory or this will break. this was breaking for me when my playingSounds.size() was equal to 140
Upvotes: 1