SFML内部OpenAL错误

SFML Internal OpenAL error

本文关键字:错误 OpenAL 内部 SFML      更新时间:2023-10-16

我有一个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与有关

还好我发现了错误

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

为了帮助其他有这个问题的人,请确保你的记忆中的sf::声音永远不会超过140,否则就会崩溃。当我的playingounds.size()等于140 时,这对我来说是个突破