SFML community forums

Help => Audio => Topic started by: Carlo Meroni on September 26, 2014, 08:34:21 pm

Title: Static sf::Sound cause the application to crash on MAC
Post by: Carlo Meroni on September 26, 2014, 08:34:21 pm
Hi,

While I was creating a game on Mac OS X I noticed that if I declare a static sf :: Sound variable and I set a SoundBuffer to it, then when I close the application it crash with bad errors.
The problem is in the sf::Sound destructor.
On windows everything works fine (with visual studio compiler).

Here is minimal code example:
//=======================
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
#include <map>

//=======================
#include "ResourcePath.hpp"

//======================
using namespace sf;

//static sound declaration
static sf::Sound snd;

int main()
{
    sf::Window win;
        win.create(VideoMode(1100, 700), "TEST", Style::Titlebar | Style::Close);
        win.setVerticalSyncEnabled(true);

    sf::SoundBuffer sndb;
    sndb.loadFromFile(resourcePath() + "Greenkey.wav");
    snd.setBuffer(sndb);
    snd.play();

        while (win.isOpen())
        {
                Event ev;
                while (win.pollEvent(ev)) {
                        switch (ev.type) {
                        case Event::Closed:
                                win.close();
                                break;
                        }
                }

                win.display();
        }

        return EXIT_SUCCESS;
}
 

Here is what XCode says:
https://www.dropbox.com/s/qgy36in0bjkytbp/Prove.png?dl=0
Title: Re: Static sf::Sound cause the application to crash on MAC
Post by: binary1248 on September 26, 2014, 10:33:02 pm
The answer (http://bit.ly/1vaXRBx)