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

Author Topic: Internal OpenAL call failed in soundbuffer.cpp (74)  (Read 4309 times)

0 Members and 1 Guest are viewing this topic.

inlinevoid

  • Newbie
  • *
  • Posts: 49
    • MSN Messenger - inlinevoidmain@gmail.com
    • AOL Instant Messenger - inlinevoid
    • View Profile
    • Email
Internal OpenAL call failed in soundbuffer.cpp (74)
« on: February 05, 2010, 04:38:18 am »
Hello,  whenever I try to load a new sound buffer and apply it to a sound class in a vector I get this error message in the cmd prompt "An internal OpenAL call failed in soundbuffer.cpp (74) : AL_INVALID_OPERATION, the specified operation is not allowed in the current state"

Here is the code...

Code: [Select]

struct SoundFile
{
std::string Name;
float Vol;
SoundBuffer Buffer;
Sound Sound;
};

class Sfx
{
private:
RenderWindow & renderwindow;
vector<SoundFile> Soundtest;

public:
Sfx(RenderWindow & Screen): renderwindow(Screen){}
void Sfx::LoadSoundFile(std::string filename, float Volume);
};

void Sfx::LoadSoundFile(std::string filename, float Volume)
{
Soundtest.resize(Soundtest.capacity()+1);
Soundtest.at(Soundtest.size()-1).Buffer.LoadFromFile(filename);
Soundtest.at(Soundtest.size()-1).Name = filename;
Soundtest.at(Soundtest.size()-1).Vol = Volume;
Soundtest.at(Soundtest.size()-1).Sound.SetBuffer(Soundtest.at(Soundtest.size()-1).Buffer);
Soundtest.at(Soundtest.size()-1).Sound.SetVolume(Volume);

cout << Soundtest.size()-1 << " loaded: " << filename << endl;
}


I call LoadSoundFile("sound.wav", 100) from main and the first one loads fine without any error.  Anyone other one I load after that will give me that error message.  The program doesn't crash or anything it just shows the error in the cmd window while the program is running.  The message appears when I call Soundtest.resize(Soundtest.capacity()+1).  Any ideas?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Internal OpenAL call failed in soundbuffer.cpp (74)
« Reply #1 on: February 05, 2010, 08:05:15 am »
Hi

There are at least two major problems in your code.

1. capacity() returns the amount of memory that is allocated for the vector, not the actual number of elements. It may lead to "gaps" in your vector: when you add 1 element with resize, the capacity may be increased a lot more (typically multiplied by a factor > 1).

2. Your SoundFile class doesn't handle properly the copy. After a copy, the instance's sound will still point to the sound buffer of the copy instead of being updated with its own buffer. You should define a copy constructor to fix this. This is very well explained at the end of the sound tutorial.

A correct solution would be:
Code: [Select]
struct SoundFile
{
   SoundFile(const SoundFile& copy) : Name(copy.Name), Vol(Copy.Vol), Buffer(Copy.Buffer), Sound(Copy.Sound)
   {
      Sound.SetBuffer(Buffer);
   }

   std::string Name;
   float Vol;
   SoundBuffer Buffer;
   Sound Sound;
};

void Sfx::LoadSoundFile(std::string filename, float Volume)
{
   SoundFile Sound;
   if (Sound.Buffer.LoadFromFile(filename))
   {
      Sound.Name = filename;
      Sound.Vol = Volume;
      Sound.Sound.SetBuffer(Sound.Buffer);
      Sound.Sound.SetVolume(Volume);

      cout << Soundtest.size() << " loaded: " << filename << endl;

      Soundtest.push_back(Sound);
   }
}

(not tested)
Laurent Gomila - SFML developer

inlinevoid

  • Newbie
  • *
  • Posts: 49
    • MSN Messenger - inlinevoidmain@gmail.com
    • AOL Instant Messenger - inlinevoid
    • View Profile
    • Email
Internal OpenAL call failed in soundbuffer.cpp (74)
« Reply #2 on: February 06, 2010, 05:06:46 am »
Thanks Laurent, I'll mess around with it a bit tonight and see if I can get it working or not.

Btw the capacity() was size() before,  I changed it just before I pasted the code. :)

Rayan jutt

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Re: Internal OpenAL call failed in soundbuffer.cpp (74)
« Reply #3 on: September 11, 2013, 07:22:22 pm »
i am also facing this problem ... where should i copy this code ?