SFML内部OpenAL错误

时间:2014-10-08 20:35:11

标签: c++ audio sfml

我有一个SoundLoader类,它将一些wav文件加载到声音缓冲区的地图中,然后我可以调用一个名为PlaySound的方法,它采用枚举来播放声音,这是我的方法

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();
    }

}
}

然而,我正在测试我的游戏,一分钟左右一切都很好,但突然之间我得到了这个错误

An internal OpenAL call failed in SoundSource.cpp (181) : AL_INVALID_NAME, an unacceptable name has been specified

我在做什么导致这个?附:我的声音加载器只有60行代码,所以不确定181与

有什么关系

1 个答案:

答案 0 :(得分:1)

好吧我发现了我的错误

if (playingSounds.at(i).getStatus() != sf::Sound::Playing && location == -1)
        {
            location = i;
        }

只是为了帮助任何其他有这个问题的人,确保你的内存永远不会超过140 sf :: Sounds,否则会破坏。当我的playSounds.size()等于140

时,这对我有用