C++ SFML内部打开错误

C++ SFML内部打开错误,c++,audio,sfml,C++,Audio,Sfml,我有一个SoundLoader类,它将一些wav文件加载到soundbuffers的映射中,然后我可以调用一个名为PlaySound的方法,该方法使用枚举来播放声音,下面是我的方法 void SoundLoader::PlaySound(SoundNames soundName) { if (playingSounds.size() == 0) { playingSounds.push_back(sf::Sound()); playingSounds.at(0).setBuff

我有一个SoundLoader类,它将一些wav文件加载到soundbuffers的映射中,然后我可以调用一个名为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();
    }

}
}

我是怎么做的?另外,我的soundloader只有60行代码,因此不确定181与什么有关

没问题,我发现了错误

if (playingSounds.at(i).getStatus() != sf::Sound::Playing && location == -1)
        {
            location = i;
        }
为了帮助其他有此问题的人,请确保您的内存中的sf::Sounds数不超过140,否则会中断。当playingSounds.size()等于140时,这对我来说是一个突破

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