Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Music hangs the app with PhysFS  (Read 801 times)

0 Members and 1 Guest are viewing this topic.

MrOnlineCoder

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
sf::Music hangs the app with PhysFS
« on: December 22, 2017, 01:34:49 pm »
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

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.

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Re: sf::Music hangs the app with PhysFS
« Reply #1 on: January 28, 2018, 11:10:36 pm »
Did you try to pause your app while it's using 100% CPU to see what's the callstack of the different threads at that moment?
Want to play movies in your SFML application? Check out sfeMovie!

FRex

  • Hero Member
  • *****
  • Posts: 1843
    • View Profile
    • My GitHub Page
    • Email
Re: sf::Music hangs the app with PhysFS
« Reply #2 on: January 29, 2018, 01:09:26 am »
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);
}
 
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi