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

Author Topic: sf::Sound won't play, unhandled exception when closed  (Read 3216 times)

0 Members and 2 Guests are viewing this topic.

gmaslin

  • Newbie
  • *
  • Posts: 3
    • View Profile
sf::Sound won't play, unhandled exception when closed
« on: March 25, 2013, 02:50:32 am »
Hi all,
             Played around with this quite a lot and I'm sure the problem is on my end.  I'm doing something very simple at the moment.
int main()
{
sf::SoundBuffer soundBuffer;   
soundBuffer.loadFromFile("ball.wav");
                               
sf::Sound soundToPlay(soundBuffer);
soundToPlay.setLoop(true);
soundToPlay.play();
}

I never get a sound.  When I close the application, I receive an "Unhandled exception at 0x77b715de in myGameIsGod.exe: 0xC0000005: Access violation reading location 0xfeeefeee."  If I click break, it takes me to
AudioDevice::~AudioDevice()
{
    // Destroy the context
    alcMakeContextCurrent(NULL);
    if (audioContext)
        alcDestroyContext(audioContext);

    // Destroy the device
    if (audioDevice)
        alcCloseDevice(audioDevice);
}
The break occurs at alcCloseDevice(audioDevice).

I'm using VS2010 and SFML2.0.  If I take out the sound part, there are no issues.  If I leave the code in, but prevent the sound from happening, there are no issues.  I have openal32 and libsndfile-1 in my project folder.  I have sfml-audio-d-2.dll in my project folder and sfml-audio-d.lib linked.

The one part I'm not sure of is that I have to use the x86 openal32 and libsndfile-1 even though I'm on a 64-bit system.  If I use the 64-bit ones, I receive an "unable to start application" message.

Also, I tried redownloading openal32 and libsndfile-1 as part of the sfml 2.0 snapshot, no luck.  I also recompiled the libraries with nmake, no luck again.

Any thoughts on what I'm doing wrong?  Let me know if you need more information.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10987
    • View Profile
    • development blog
    • Email
Re: sf::Sound won't play, unhandled exception when closed
« Reply #1 on: March 25, 2013, 02:55:28 am »
int main()
{
sf::SoundBuffer soundBuffer;   
soundBuffer.loadFromFile("ball.wav");
                               
sf::Sound soundToPlay(soundBuffer);
soundToPlay.setLoop(true);
soundToPlay.play();
}

I never get a sound.
If you're really using that code it's not surprising. The application runs out of scope, thus closes, before it gets a chance to play the sound.

When I close the application, I receive an "Unhandled exception at 0x77b715de in myGameIsGod.exe: 0xC0000005: Access violation reading location 0xfeeefeee."  If I click break, it takes me to
I'd say issue #30... ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

gmaslin

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: sf::Sound won't play, unhandled exception when closed
« Reply #2 on: March 25, 2013, 03:14:55 am »
Thanks for the quick response.  Nope, it's really how I am using it.  Declaring soundBuffer and soundToPlay in a Engine.h, then the loadFromFile, setBuffer, and play occur off key press that is detected within Engine.cpp.

Good to hear that the issue has already been identified and at least that part isn't on my end.

Here is a simple version of the code.

//Engine.h
#ifndef GAME_ENGINE_H
#define GAME_ENGINE_H

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

class Engine
{
public:
    void gameRun();
private:
        sf::SoundBuffer soundBuffer;
        sf::Sound soundToPlay;
};

#endif
 

//Engine.cpp
void Engine::gameRun()
{
        while(myWindow.isOpen())
        {
                while(myWindow.pollEvent(pEvent))
                {
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                                myWindow.close();
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                        {
                                soundBuffer.loadFromFile("Windows Critical Stop.wav");
                                soundToPlay.setBuffer(soundBuffer);
                                soundToPlay.setLoop(true);
                                soundToPlay.play();
                        }
                }
               
        }
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10987
    • View Profile
    • development blog
    • Email
Re: sf::Sound won't play, unhandled exception when closed
« Reply #3 on: March 25, 2013, 03:29:31 am »
What about this example:
#include <SFML/Audio.hpp>
#include <SFML/Window.hpp>

int main()
{
        sf::SoundBuffer soundBuffer;
    sf::Sound soundToPlay;

    soundBuffer.loadFromFile("Windows Critical Stop.wav");
        soundToPlay.setBuffer(soundBuffer);
        soundToPlay.setLoop(true);
        soundToPlay.play();

        while(!sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
        {
                sf::sleep(sf::milliseconds(200));
        }
}
 

Btw. you should never load the same in a while loop, just load it once and then use it when ever wanted.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

gmaslin

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: sf::Sound won't play, unhandled exception when closed
« Reply #4 on: March 25, 2013, 03:36:58 am »
No dice.  Speakers work for other things, volume is up and not muted.

 

anything