SFML community forums
Help => Audio => Topic started by: lordimmortal 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:
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:
(http://i51.tinypic.com/15710lu.jpg)
As always, any help and replies are greatly appreciated.
-
Bump.
Anyone have any idea what's wrong?
-
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
-
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:
(http://i54.tinypic.com/16iiexw.jpg)
Here is what I changed it to:
SFML_Audio.cpp:
#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
#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?
-
can i see the whole program?
-
It's quite a large one, what specifically would you like to look at?
-
where Ever PlaySoundSFML is being used.
you can use
http://pastebin.com/
for that,
-
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
-
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
-
No dice. I changed it to:
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.
-
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.
-
Do you use SFML 2? If so, have you recompiled it?
No, I'm using SFML 1.6
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
-
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 ;)
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?
-
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).
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.
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.
-
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.void LoadSoundSFML()
{
// Load a sound buffer from a wav file
if (!Buffer.LoadFromFile("Test3.wav"))
return;
}
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.