Hello! I am working on a game and I load all resources from zip file using PhysFS. I am using this class from SFML wiki: https://github.com/SFML/SFML/wiki/Source:-PhysicsFS-Input-Stream (https://github.com/SFML/SFML/wiki/Source:-PhysicsFS-Input-Stream)
And I have noticed strange behaivour: if I open PhysFsStream once, open music from it, then everything is OK. But if I do this again (to change current music) - my application hangs (100% of CPU core).
Minimal code (all variables are class members):
//GameState
//init() - called once when game state is shown up
pfsStream.open("music/1.ogg");
music.openFromStream(pfsStream);
music.play();
//input() - called on input.
music.stop();
pfsStream.open("music/2.ogg");
music.openFromStream(pfsStream);
music.play();
My PhysFS setup is fully wokrable (I use the same way to load textures, sounds, they are all working and loaded correctly).
After debugging application for some time, I ended on this code in sf::SoundStream:
void SoundStream::stop()
{
// Request the thread to terminate
{
Lock lock(m_threadMutex);
m_isStreaming = false;
}
...
I wil really appreciate any help concerning this topic, maybe newer version of PhysFS stream or any possible fixes.
I just did this and it works for me as expected (it plays first song, I press enter once and then the second song plays until I press enter again and the program quits). You need to investigate deeper, test this code and give us a self contained example that fails.
int main(int argc, char ** argv)
{
if(!PHYSFS_init(argv[0]))
{
std::fprintf(stderr, "%s\n", PHYSFS_getLastError());
return 1;
}
if(!PHYSFS_addToSearchPath("test.zip", true))
{
std::fprintf(stderr, "%s\n", PHYSFS_getLastError());
return 1;
}
PhysFsStream stream;
sf::Music music;
std::string a;
stream.open("music/test1.ogg");
music.openFromStream(stream);
music.play();
std::cout << "press enter to continue" << std::endl;
std::getline(std::cin, a);
music.stop();
stream.open("music/test2.ogg");
music.openFromStream(stream);
music.play();
std::cout << "press enter to continue" << std::endl;
std::getline(std::cin, a);
}