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

Author Topic: crash with sf::Music  (Read 2042 times)

0 Members and 1 Guest are viewing this topic.

iride

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
crash with sf::Music
« 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
« Last Edit: May 03, 2015, 06:59:37 pm by iride »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
AW: crash with sf::Music
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

iride

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Re: crash with sf::Music
« Reply #2 on: May 03, 2015, 07:25:15 pm »
now the program crashes with "access violation" error

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
AW: crash with sf::Music
« Reply #3 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything