SFML community forums

Help => Audio => Topic started by: Giovanni on May 06, 2011, 12:31:30 pm

Title: Crashing on loading a sound
Post by: Giovanni on May 06, 2011, 12:31:30 pm
Hello,
I'm trying to make a soundmanager using sfml audio, but I'm having some problems on the loading. I searched in this website and tried to do everything of what you said, but still doesn't work :(

Here's the loading:

Code: [Select]
int SoundManager::LoadSound(string strFileName)
{
sf::SoundBuffer *buffer = new sf::SoundBuffer();

if (!buffer->LoadFromFile(strFileName))
{
buffer->~SoundBuffer();
return -1;
}

for (size_t i = 0; i < m_buffers.size(); i++)
{
if (!m_buffers[i])
{
m_buffers[i] = buffer;
return i;
}
}

m_buffers.push_back(buffer);
return m_buffers.size() - 1;
//return 0;
}


if I made a really stupid mistake, please don't bother me, I'm a newbie as a programmer so be patient.  :oops:
Title: Crashing on loading a sound
Post by: Laurent on May 06, 2011, 01:10:38 pm
Where does it crash? (use the debugger -- F5)

Code: [Select]
buffer->~SoundBuffer();
You must never call a destructor explicitely. Here you must call delete, since you allocated the object with new.
Title: Crashing on loading a sound
Post by: Giovanni on May 06, 2011, 01:43:13 pm
Quote from: "Laurent"
Code: [Select]
buffer->~SoundBuffer();
You must never call a destructor explicitely. Here you must call delete, since you allocated the object with new.


thanks :}

anyway it crashes here:
if (!buffer->LoadFromFile(strFileName))

I'm compiling in release mode, the libs to use are sfml-audio-s.lib and sfml-system-s.lib, aren't they?

Because I think I messed up the vcpp configurations. :S
Title: Crashing on loading a sound
Post by: Laurent on May 06, 2011, 01:44:49 pm
Quote
I'm compiling in release mode, the libs to use are sfml-audio-s.lib and sfml-system-s.lib, aren't they?

Yes.

You should compile in debug mode and run the debugger, it will tell you what's wrong ;)

Also, make sure that your version of Visual Studio matches the one of the libs that you're using (for example VC++ 2010 can't use VC++ 2008 libraries).
Title: Crashing on loading a sound
Post by: Giovanni on May 06, 2011, 02:49:53 pm
Quote from: "Laurent"
Quote
I'm compiling in release mode, the libs to use are sfml-audio-s.lib and sfml-system-s.lib, aren't they?

Yes.

You should compile in debug mode and run the debugger, it will tell you what's wrong ;)

Also, make sure that your version of Visual Studio matches the one of the libs that you're using (for example VC++ 2010 can't use VC++ 2008 libraries).


I made it!
you're the best man, thank you! :D
Title: Crashing on loading a sound
Post by: Laurent on May 06, 2011, 02:57:13 pm
What was the problem?
Title: Crashing on loading a sound
Post by: Giovanni on May 06, 2011, 07:30:46 pm
Quote from: "Laurent"
What was the problem?


vc++2010, I had to compile the libs again

thank you,
your sfml is just awesome! :D