Improved OpenAL sound handler stability and fixed leaks.

git-svn-id: http://svn.purei.org/purei/trunk@1189 b36208d7-6611-0410-8bec-b1987f11c4a2
This commit is contained in:
jpd002 2013-09-05 05:01:33 +00:00
parent d3050f28bb
commit 2b8c8f23ba
2 changed files with 11 additions and 6 deletions

View File

@ -19,15 +19,16 @@ m_lastUpdateTime(0),
m_mustSync(true)
{
m_context.MakeCurrent();
ALuint bufferNames[MAX_BUFFERS];
alGenBuffers(MAX_BUFFERS, bufferNames);
alGenBuffers(MAX_BUFFERS, m_bufferNames);
CHECK_AL_ERROR();
m_availableBuffers.insert(m_availableBuffers.begin(), bufferNames, bufferNames + MAX_BUFFERS);
Reset();
}
CSH_OpenAL::~CSH_OpenAL()
{
Reset();
alDeleteBuffers(MAX_BUFFERS, m_bufferNames);
CHECK_AL_ERROR();
}
CSoundHandler* CSH_OpenAL::HandlerFactory()
@ -40,13 +41,16 @@ void CSH_OpenAL::Reset()
m_source.Stop();
ALint sourceState = m_source.GetState();
assert(sourceState == AL_INITIAL || sourceState == AL_STOPPED);
RecycleBuffers();
assert(m_availableBuffers.size() == MAX_BUFFERS);
alSourcei(m_source, AL_BUFFER, 0);
CHECK_AL_ERROR();
m_availableBuffers.clear();
m_availableBuffers.insert(m_availableBuffers.begin(), m_bufferNames, m_bufferNames + MAX_BUFFERS);
}
void CSH_OpenAL::RecycleBuffers()
{
unsigned int bufferCount = m_source.GetBuffersProcessed();
CHECK_AL_ERROR();
if(bufferCount != 0)
{
ALuint* bufferNames = reinterpret_cast<ALuint*>(alloca(sizeof(ALuint) * bufferCount));

View File

@ -36,6 +36,7 @@ private:
BufferList m_availableBuffers;
uint64 m_lastUpdateTime;
bool m_mustSync;
ALuint m_bufferNames[MAX_BUFFERS];
};
#endif