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

Author Topic: Audio Crash  (Read 10497 times)

0 Members and 1 Guest are viewing this topic.

lordimmortal

  • Newbie
  • *
  • Posts: 8
    • View Profile
Audio Crash
« on: July 29, 2011, 08:35:04 pm »
I have been trying to get the audio of SFML working but it crashes in a strange way.

The game crashes when trying to reference 0x00000000. It seems to be trying to access some 64-bit code which is strange since there aren't any different library sets from SFML beyond different OSes, or so I can tell. I am on Windows XP 32-bit. Here is the code:

Code: [Select]
void LoadSound()
{
        sf::SoundBuffer Buffer;
        sf::Sound               Sound;

        if (!Buffer.LoadFromFile("Test.wav"))
        {
                // Error
                return;
        }

        Sound.SetBuffer(Buffer);

        Sound.SetLoop(true);
        Sound.SetVolume(100);

        Sound.Play();
}


I used a piece of music on my computer to test, it crashed that way, so I thought it might be long/big of a file (which was supported by the tutorial of music on SFML). I cut it down to about half a second and that didn't work, so I tried using a sound effect that came with the samples of SFML. That didn't work either.

The error:


As always, any help and replies are greatly appreciated.

lordimmortal

  • Newbie
  • *
  • Posts: 8
    • View Profile
Audio Crash
« Reply #1 on: July 30, 2011, 01:29:10 am »
Bump.

Anyone have any idea what's wrong?

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
Audio Crash
« Reply #2 on: July 30, 2011, 10:40:23 pm »
It looks like your creating the sound buffer inside the LoadSound function, but when its ending it goes out of scope and is destroyed, but still trying to be played, try making the Sound and soundbuffer global to see if it stops crashing
John Carmack can Divide by zer0.

lordimmortal

  • Newbie
  • *
  • Posts: 8
    • View Profile
Audio Crash
« Reply #3 on: July 31, 2011, 03:05:14 am »
Quote
It looks like your creating the sound buffer inside the LoadSound function, but when its ending it goes out of scope and is destroyed, but still trying to be played, try making the Sound and soundbuffer global to see if it stops crashing


Thanks for the reply!

I made those two variables global. It did not crash when it tried to play the sound, but DID when I closed the program. Also, it did not play the sound. I tried playing two different sounds and specifying a loop and max volume but no dice.

Error:


Here is what I changed it to:

SFML_Audio.cpp:
Code: [Select]
#include "SFML_Audio.h"

sf::SoundBuffer Buffer;
sf::Sound Sound(Buffer);

void PlaySoundSFML()
{
    // Load a sound buffer from a wav file
    if (!Buffer.LoadFromFile("footsteps.wav"))
        return;

    // Play sound instance
    Sound.Play();
}


SFML_Audio.h
Code: [Select]
#pragma once

#include <SFML/Audio.hpp>

void PlaySoundSFML();

extern sf::SoundBuffer Buffer;
extern sf::Sound Sound;


I do not know if the variables need the externality but it shouldn't have caused the crash either way, correct?

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
Audio Crash
« Reply #4 on: July 31, 2011, 04:25:07 am »
can i see the whole program?
John Carmack can Divide by zer0.

lordimmortal

  • Newbie
  • *
  • Posts: 8
    • View Profile
Audio Crash
« Reply #5 on: July 31, 2011, 04:40:32 am »
It's quite a large one, what specifically would you like to look at?

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
Audio Crash
« Reply #6 on: July 31, 2011, 05:15:42 am »
where Ever PlaySoundSFML is being used.
you can use
http://pastebin.com/
for that,
John Carmack can Divide by zer0.

lordimmortal

  • Newbie
  • *
  • Posts: 8
    • View Profile
Audio Crash
« Reply #7 on: July 31, 2011, 05:33:03 am »
Oh, the call to PlaySoundSFML() isn't too complicated. It just plays the sound when the E key is pressed, and all other input works as intended.

But, here is the entirety of it (that pertains to PlaySoundSFML() anyway):
http://pastebin.com/5ZRGnfnj

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
Audio Crash
« Reply #8 on: July 31, 2011, 06:38:01 am »
part of the problem might be because your reloading the .wav every time you press E, try loading it once, setting the buffer to the sound After you've loaded using .SetBuffer( ... ) then simply do Sound.Play() in the function
John Carmack can Divide by zer0.

lordimmortal

  • Newbie
  • *
  • Posts: 8
    • View Profile
Audio Crash
« Reply #9 on: July 31, 2011, 07:08:56 am »
No dice. I changed it to:

Code: [Select]
sf::SoundBuffer Buffer;
sf::Sound Sound(Buffer);

void LoadSoundSFML()
{
// Load a sound buffer from a wav file
    if (!Buffer.LoadFromFile("Test3.wav"))
        return;
}

void PlaySoundSFML()
{
    // Play sound instance
    Sound.Play();
}


with LoadSoundSFML() called on program startup and PlaySoundSFML() on every E key press. It is also noteworthy to say that it crashes on shut down even without pressing E.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Audio Crash
« Reply #10 on: July 31, 2011, 10:35:00 am »
Do you use SFML 2? If so, have you recompiled it?

By the way, it would be much easier to help you if you provided a small, complete code example that still reproduces this error. Try to minimize your code as much as possible and remove all the irrelevant details.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

lordimmortal

  • Newbie
  • *
  • Posts: 8
    • View Profile
Audio Crash
« Reply #11 on: July 31, 2011, 11:12:04 pm »
Quote
Do you use SFML 2? If so, have you recompiled it?


No, I'm using SFML 1.6

Quote
By the way, it would be much easier to help you if you provided a small, complete code example that still reproduces this error. Try to minimize your code as much as possible and remove all the irrelevant details.


This is where it gets strange. I placed in what I'm using for SFML into a small program that uses DX for input (what I'm using in my other program for input and graphics). And it does not crash on shut down or any other time but it does not play the sound. I must be missing something.

Here it is:
http://pastebin.com/qFA6TGEw

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Audio Crash
« Reply #12 on: August 01, 2011, 01:27:35 am »
Quote from: "lordimmortal"
This is where it gets strange. I placed in what I'm using for SFML into a small program that uses DX for input (what I'm using in my other program for input and graphics).
Please provide a example that uses only SFML, so that we understand everything and can exclude other error sources. A single file with only a main() function, no fancy stuff. And it would be nice if the error still occurred ;)

Quote from: "lordimmortal"
And it does not crash on shut down or any other time but it does not play the sound. I must be missing something.
Are you sure that the sound is loaded correctly? I ask because your "error handling" in LoadSoundSFML() is completely useless.

Have you tried the SFML Audio sample?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

lordimmortal

  • Newbie
  • *
  • Posts: 8
    • View Profile
Audio Crash
« Reply #13 on: August 01, 2011, 02:10:45 am »
Quote
Please provide a example that uses only SFML, so that we understand everything and can exclude other error sources. A single file with only a main() function, no fancy stuff. And it would be nice if the error still occurred Wink


The fact that it does not produce an error with DX included shows that DX is not the error. In my main program, the only time it crashes is when SFML code is loaded (commenting out calls to LoadSoundSFML makes no crash on shut down but putting it back in does crash).

Quote
Are you sure that the sound is loaded correctly? I ask because your "error handling" in LoadSoundSFML() is completely useless.


I have absolutely NO IDEA what I'm doing when it comes to SFML. The tutorial on audio helped extremely little in me understanding this. I also have to ask where you saw any thing that pertained to error handling in my SFML code. Everything in it is ripped straight from the tutorial.

Quote
Have you tried the SFML Audio sample?

Yes. That works. I don't know why it works and there is nothing related to audio that is separating my code and the audio sample beyond the sample displaying information to the screen.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Audio Crash
« Reply #14 on: August 01, 2011, 12:39:58 pm »
Quote from: "lordimmortal"
I also have to ask where you saw any thing that pertained to error handling in my SFML code. Everything in it is ripped straight from the tutorial.
You don't react to loading failures, although the code makes the impression of doing so.
Code: [Select]
void LoadSoundSFML()
{
// Load a sound buffer from a wav file
    if (!Buffer.LoadFromFile("Test3.wav"))
        return;
}


Quote from: "lordimmortal"
Quote
Have you tried the SFML Audio sample?
Yes. That works. I don't know why it works and there is nothing related to audio that is separating my code and the audio sample beyond the sample displaying information to the screen.
Then adapt the Audio sample step by step until you finally get your code. Like this, you see when exactly the error occurs, and therefore where it occurs.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: