Hi Forum,
so this is a rather complicated problem with sf::Sound.
I face a problem when i create a std::map with an std::string as the key-value and a sf::Sound as the second argument ! I know its not recommended to save an sf::Sound to container as it always needs to point to an sf::SoundBuffer ! But in my case i wanted to go with that solution so i created an std::vector that would store my sf::SoundBuffer ! Before i go on heres the Code:
Header(minimal example):
std::map <std::string, sf::Sound> Sounds;
std::vector<sf::SoundBuffer> soundBuffer;
So here are both map and vector !
Now the implementation from a function that stores a loaded sf::SoundBuffer in a Vector and an sf::Sound to
a Map
Implementation:
sf::SoundBuffer buffer;
if (buffer.loadFromFile(path))
{
soundBuffer.push_back(buffer);
//sound_.setBuffer(soundBuffer.back());
//Sounds.insert(std::pair<std::string, sf::Sound>(name, sf::Sound{soundBuffer.back()}));
Sounds.emplace(name, sf::Sound{ soundBuffer.back() });
return true;
}
As you can see, i tried out a lot of things
So wheres now the problem ? When i try to play multiple sounds only the last one added is functioning.The other two(in my case i added 3 sounds as an wav) get nullptr(first screenshot).
And the sf::SoundBuffer Vector is perfectly working !
I have no idea what i did wrong(i think it isnt an out of scope problem, because it should be prevented through the Vector).
I hope u can help me !
Thanks