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

Author Topic: Crashing on loading a sound  (Read 2649 times)

0 Members and 1 Guest are viewing this topic.

Giovanni

  • Newbie
  • *
  • Posts: 4
    • View Profile
Crashing on loading a sound
« 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:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Crashing on loading a sound
« Reply #1 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.
Laurent Gomila - SFML developer

Giovanni

  • Newbie
  • *
  • Posts: 4
    • View Profile
Crashing on loading a sound
« Reply #2 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Crashing on loading a sound
« Reply #3 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).
Laurent Gomila - SFML developer

Giovanni

  • Newbie
  • *
  • Posts: 4
    • View Profile
Crashing on loading a sound
« Reply #4 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Crashing on loading a sound
« Reply #5 on: May 06, 2011, 02:57:13 pm »
What was the problem?
Laurent Gomila - SFML developer

Giovanni

  • Newbie
  • *
  • Posts: 4
    • View Profile
Crashing on loading a sound
« Reply #6 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