SFML community forums

Help => Audio => Topic started by: iride on May 03, 2015, 06:54:36 pm

Title: crash with sf::Music
Post by: iride on May 03, 2015, 06:54:36 pm
I'm using phsfsstream class from here: https://github.com/SFML/SFML/wiki/Source%3A-PhysicsFS-Input-Stream

#include "PhysfsStream.h"
#include <SFML/Audio.hpp>
#include <iostream>

int main(int argc, char* argv[])
{      
        PHYSFS_init(argv[0]);
        PHYSFS_addToSearchPath("musics", 1);

        sf::Music music;
        PhysfsStream stream;
        stream.open("sample.ogg");
        music.openFromStream(stream);
        music.play();
       

        //music.stop(); //adding this line will prevent the program from crashing

        PHYSFS_deinit();
}

this program crashes saying "pure virtual function call", but if I stop the music before it goes out of scope, it won't crash. Is this a bug in SFML?

using visual studio 2013 and sfml 2.2
Title: AW: crash with sf::Music
Post by: eXpl0it3r on May 03, 2015, 07:15:42 pm
The stream gets destroyed before the music instance and since sf::Music runs in a separate thread, it will still try to access the destroyed stream, causing a pure virtual call.

Create the stream instance before the music instance.
Title: Re: crash with sf::Music
Post by: iride on May 03, 2015, 07:25:15 pm
now the program crashes with "access violation" error
Title: AW: crash with sf::Music
Post by: eXpl0it3r on May 03, 2015, 07:47:16 pm
Actually since the physics system gets initialized and destroyed manually, you'll most likely will have to make sure the sf::Music objects gets destroyed first, by for example placing it in its own scope.
Or you'll just make sure nothing of the phsysics system gets used anymore once it gets destroyed.