Good evening.
I was trying to make a little playlist manager for one of my games using the m3u format. The m3u-thing is working good but I decided to use dynamic allocation because sf::Music wasn't copyable.
Before that, I was playing music well before but since dynamic allocation the music is marked as playing but nothing goes out of my headphones.
Here is the part were I allocate the sf::Music instance :
m_currentMusics.clear();
for(auto &musicName : it->second)
{
sf::Music* music = new sf::Music;
if (!music->openFromFile(musicName))
{
delete music;
continue;
}
music->setVolume(m_volume);
m_currentMusics.push_back(music);
}
m_currentMusicIndex = 0;
if (m_currentMusics.size() > 0)
{
m_currentMusics[m_currentMusicIndex]->play();
}
std::cout << (m_currentMusics[m_currentMusicIndex]->getStatus() == sf::Music::Status::Playing) << std::endl;
I do got a 1 answer on stdout meaning that the song's status is set to playing. Moreover, I toke a screenshot from VS debugger in order to show you that the song is loaded in the MusicManager after a call to the concerned method :
(http://i.imgur.com/JWEZVeb.png)
Any ideas ? :)
EDIT : Sorry for this useless topic, I set the m_volume to 0.6f instead of 60.f. Time to go bed I think.
By the way, if you already use C++11, you should definitely work with std::unique_ptr instead of manual new and delete ;)
for(auto &musicName : it->second)
{
std::unique_ptr<sf::Music> music(new sf::Music);
if (!music->openFromFile(musicName))
continue; // no delete necessary!
music->setVolume(m_volume);
m_currentMusics.push_back(std::move(music)); // transfer ownership to container
}
// No delete for container elements anywhere else necessary (e.g. destructor)
For a detailed example that shows the RAII advantages, you might want to check out this thread (http://en.sfml-dev.org/forums/index.php?topic=9359.msg63566#msg63566).