SFML community forums

Help => Audio => Topic started by: Visor on April 13, 2017, 03:56:08 pm

Title: [SOLVED] OpenAL error (AL_OUT_OF_MEMORY)
Post by: Visor on April 13, 2017, 03:56:08 pm
Hello,

I get an AL error, but I have no idea what I did wrong in my code. I really don't think it's a memory problem, I have RAM 16 GB and create new sounds only if there are less than 100 sounds in the vector (I read that it can works until 256).

The first error I get is:
Quote
An internal OpenAL call failed in SoundSource.cpp(37).
Expression:
   alGenSources(1, &m_source)
Error description:
   AL_OUT_OF_MEMORY
   There is not enough memory left to execute the command.

And then, every new sound created implies this error:
Quote
An internal OpenAL call failed in SoundSource.cpp(37).
Expression:
   alSourcei(m_source, AL_BUFFER, 0)
Error description:
   AL_INVALID_NAME
   A bad name (ID) has been specified.

It's probably because of my sound manager, so here is it:
Quote

for (std::vector<sSoundManager*>::iterator iteratorSounds = m_soundManager.begin(); iteratorSounds != m_soundManager.end() ; )
   {   
      if ((*iteratorSounds)->m_bPlayed == false // Play the sound if not played yet
         && (*iteratorSounds)->m_iTimeDelay <= 0)
      {
         (*iteratorSounds)->m_bPlayed = true;
         (*iteratorSounds)->m_sound.play();
         iteratorSounds++;
      }
      else if ((*iteratorSounds)->m_bPlayed == true // Purge played sounds
         && ((*iteratorSounds)->m_sound.getStatus() == sf::Sound::Status::Stopped
         || ((*iteratorSounds)->m_bTimeToLive_enabled && (*iteratorSounds)->m_iTimeToLive <= 0)))
      {
         if ((*iteratorSounds)->m_sound.getStatus() != sf::Sound::Status::Stopped)
            (*iteratorSounds)->m_sound.stop();

         delete(*iteratorSounds);
         iteratorSounds = m_soundManager.erase(iteratorSounds);
      }
      else // Processing sounds
      {
         (*iteratorSounds)->m_iTimeDelay -= m_DeltaTime;

         if ((*iteratorSounds)->m_bTimeToLive_enabled
            && (*iteratorSounds)->m_iTimeDelay <= 0)
            (*iteratorSounds)->m_iTimeToLive -= m_DeltaTime;

         iteratorSounds++;
      }
}

I saw that "erase.()" deletes the element when it want (not instantly)... But I don't think it can be the problem.

Do anybody have an idea where the problem can be ?
Title: Re: OpenAL error (AL_OUT_OF_MEMORY)
Post by: Hapax on April 13, 2017, 09:27:22 pm
I suppose it could depend on what an "sSoundManager" object is and also how it behaves when it is deleted.
Title: Re: OpenAL error (AL_OUT_OF_MEMORY)
Post by: Visor on April 13, 2017, 09:39:23 pm
Sorry, I forfot to show the struct:

Quote

struct sSoundManager
{
public:
   sf::Sound m_sound;
   sf::Vector2f m_position;
   bool m_bPlayed;
   int m_iDistanceMin;
   int m_iDistanceMax;
   int m_iTimeToLive;
   int m_iTimeDelay;
   bool m_bTimeToLive_enabled;
   
   sSoundManager()
   {
      m_bPlayed = false;
      m_iTimeToLive = 0;
      m_iTimeDelay = 0;
      m_bTimeToLive_enabled = false;
   }
};

The sf::Sound is deleted with the *sSoundManager when calling m_soundManager.erase(iteratorSounds). Nothing strange according to me.
Title: Re: OpenAL error (AL_OUT_OF_MEMORY)
Post by: eXpl0it3r on April 13, 2017, 11:04:18 pm
What's your OS?
Title: Re: OpenAL error (AL_OUT_OF_MEMORY)
Post by: Visor on April 13, 2017, 11:49:27 pm
Windows 8.1 (64bits), I build in 32bits.

Edit: I put the OpenAL.dll from SFML_2.4.2 zip in the app's executable folder.
Title: Re: OpenAL error (AL_OUT_OF_MEMORY)
Post by: eXpl0it3r on April 14, 2017, 11:15:51 pm
How large are your 100 sounds that you load?
Title: Re: OpenAL error (AL_OUT_OF_MEMORY)
Post by: Visor on April 15, 2017, 12:32:21 am
Thank you for helping.

It's really depending on what's happening ingame, I can't really know.
I use a vector of sf::SoundBuffer with 24mb of flac loaded in at startup,
and I get the pointer I need to use it in the processing vector (the one with max 100 elements).

Most of the sounds are just alternatives (e.g multiples step sound), so I guess only the half are used at the same time in the <100 elem vector. One of them is pretty huge tho, ~10mb. All the others are less than 1mb.
Title: Re: OpenAL error (AL_OUT_OF_MEMORY)
Post by: Visor on April 21, 2017, 03:12:12 pm
Ok I think I found what was the real problem, it seems a sf::sound's pointer could have had an unexpected behavior depending on some cases.
Thank you again for trying to help !