1
0
forked from 0ad/0ad

fix for ticket 1758, not fixing the underlying problem but will limit the error messages to 1 per failed allocation and shouldn't crash anymore

This was SVN commit r12989.
This commit is contained in:
stwf 2012-12-14 03:10:03 +00:00
parent 60987d46cf
commit 012e1585b1
4 changed files with 113 additions and 88 deletions

View File

@ -39,16 +39,19 @@ CBufferItem::~CBufferItem()
AL_CHECK
Stop();
int num_processed;
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
if (num_processed > 0)
if (m_ALSource != 0)
{
ALuint* al_buf = new ALuint[num_processed];
alSourceUnqueueBuffers(m_ALSource, num_processed, al_buf);
int num_processed;
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
AL_CHECK
delete[] al_buf;
if (num_processed > 0)
{
ALuint* al_buf = new ALuint[num_processed];
alSourceUnqueueBuffers(m_ALSource, num_processed, al_buf);
AL_CHECK
delete[] al_buf;
}
}
}
@ -56,26 +59,30 @@ CBufferItem::~CBufferItem()
bool CBufferItem::IdleTask()
{
HandleFade();
if (m_LastPlay)
if (m_ALSource != 0)
{
int proc_state;
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
return (proc_state != AL_STOPPED);
}
if (GetLooping())
{
int num_processed;
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
for (int i = 0; i < num_processed; i++)
if (m_LastPlay)
{
ALuint al_buf;
alSourceUnqueueBuffers(m_ALSource, 1, &al_buf);
AL_CHECK
alSourceQueueBuffers(m_ALSource, 1, &al_buf);
int proc_state;
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
AL_CHECK
return (proc_state != AL_STOPPED);
}
if (GetLooping())
{
int num_processed;
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
for (int i = 0; i < num_processed; i++)
{
ALuint al_buf;
alSourceUnqueueBuffers(m_ALSource, 1, &al_buf);
AL_CHECK
alSourceQueueBuffers(m_ALSource, 1, &al_buf);
AL_CHECK
}
}
}
@ -84,8 +91,8 @@ bool CBufferItem::IdleTask()
void CBufferItem::Attach(CSoundData* itemData)
{
AL_CHECK
if (itemData != NULL)
AL_CHECK
if ( (itemData != NULL) && (m_ALSource != 0) )
{
m_SoundData = itemData->IncrementCount();
alSourceQueueBuffers(m_ALSource, m_SoundData->GetBufferCount(),(const ALuint *) m_SoundData->GetBufferPtr());

View File

@ -137,9 +137,7 @@ bool CSoundBase::InitOpenAL()
{
alGetError(); /* clear error */
alGenSources(1, &m_ALSource);
long anErr = alGetError();
AL_CHECK
ALenum anErr = alGetError();
if (anErr == AL_NO_ERROR)
{
@ -160,9 +158,12 @@ bool CSoundBase::InitOpenAL()
bool CSoundBase::IsPlaying()
{
int proc_state;
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
AL_CHECK
ALenum proc_state = AL_STOPPED;
if ( m_ALSource != 0 )
{
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
AL_CHECK
}
return (proc_state == AL_PLAYING);
}
@ -179,7 +180,7 @@ bool CSoundBase::IdleTask()
void CSoundBase::SetLocation (const CVector3D& position)
{
if ( m_ALSource )
if ( m_ALSource != 0 )
{
alSourcefv(m_ALSource,AL_POSITION, position.GetFloatArray());
AL_CHECK
@ -200,10 +201,11 @@ bool CSoundBase::HandleFade()
Stop();
else if (curGain == m_EndVolume)
{
alSourcef(m_ALSource, AL_GAIN, curGain);
if (m_ALSource != 0)
alSourcef(m_ALSource, AL_GAIN, curGain);
ResetFade();
}
else
else if (m_ALSource != 0)
alSourcef(m_ALSource, AL_GAIN, curGain);
AL_CHECK
@ -219,8 +221,11 @@ bool CSoundBase::GetLooping()
void CSoundBase::SetLooping(bool loops)
{
m_Looping = loops;
alSourcei(m_ALSource, AL_LOOPING, loops ? AL_TRUE : AL_FALSE);
AL_CHECK
if (m_ALSource != 0)
{
alSourcei(m_ALSource, AL_LOOPING, loops ? AL_TRUE : AL_FALSE);
AL_CHECK
}
}
void CSoundBase::Play()
@ -261,16 +266,19 @@ void CSoundBase::PlayLoop()
void CSoundBase::FadeToIn(ALfloat newVolume, double fadeDuration)
{
int proc_state;
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
if (proc_state == AL_PLAYING)
{
m_StartFadeTime = timer_Time();
m_EndFadeTime = m_StartFadeTime + fadeDuration;
alGetSourcef(m_ALSource, AL_GAIN, &m_StartVolume);
m_EndVolume = newVolume;
if (m_ALSource != 0)
{
ALenum proc_state;
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
if (proc_state == AL_PLAYING)
{
m_StartFadeTime = timer_Time();
m_EndFadeTime = m_StartFadeTime + fadeDuration;
alGetSourcef(m_ALSource, AL_GAIN, &m_StartVolume);
m_EndVolume = newVolume;
}
AL_CHECK
}
AL_CHECK
}
void CSoundBase::PlayAsMusic()

View File

@ -43,15 +43,19 @@ CSoundItem::~CSoundItem()
AL_CHECK
Stop();
alSourcei(m_ALSource, AL_BUFFER, 0);
AL_CHECK
if (m_ALSource != 0)
{
alSourcei(m_ALSource, AL_BUFFER, 0);
AL_CHECK
}
}
bool CSoundItem::IdleTask()
{
HandleFade();
if (m_LastPlay)
if (m_LastPlay && (m_ALSource != 0) )
{
int proc_state;
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
@ -63,7 +67,7 @@ bool CSoundItem::IdleTask()
void CSoundItem::Attach(CSoundData* itemData)
{
if (itemData != NULL)
if (itemData != NULL && (m_ALSource != 0) )
{
m_SoundData = itemData->IncrementCount();
alSourcei(m_ALSource, AL_BUFFER, m_SoundData->GetBuffer());

View File

@ -36,16 +36,19 @@ CStreamItem::CStreamItem(CSoundData* sndData)
CStreamItem::~CStreamItem()
{
Stop();
int num_processed;
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
if (num_processed > 0)
if (m_ALSource != 0)
{
ALuint* al_buf = new ALuint[num_processed];
alSourceUnqueueBuffers(m_ALSource, num_processed, al_buf);
AL_CHECK
delete[] al_buf;
int num_processed;
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
if (num_processed > 0)
{
ALuint* al_buf = new ALuint[num_processed];
alSourceUnqueueBuffers(m_ALSource, num_processed, al_buf);
AL_CHECK
delete[] al_buf;
}
}
}
@ -55,39 +58,42 @@ bool CStreamItem::IdleTask()
HandleFade();
AL_CHECK
int proc_state;
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
AL_CHECK
if (proc_state == AL_STOPPED)
if (m_ALSource != 0)
{
if (m_LastPlay)
return (proc_state != AL_STOPPED);
}
else if (m_SoundData != NULL)
{
COggData* theData = (COggData*)m_SoundData;
int proc_state;
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
AL_CHECK
if (! theData->IsFileFinished())
if (proc_state == AL_STOPPED)
{
int num_processed;
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
AL_CHECK
if (num_processed > 0)
{
ALuint* al_buf = new ALuint[num_processed];
alSourceUnqueueBuffers(m_ALSource, num_processed, al_buf);
AL_CHECK
int didWrite = theData->FetchDataIntoBuffer(num_processed, al_buf);
alSourceQueueBuffers(m_ALSource, didWrite, al_buf);
AL_CHECK
delete[] al_buf;
}
if (m_LastPlay)
return (proc_state != AL_STOPPED);
}
else if (GetLooping())
else if (m_SoundData != NULL)
{
theData->ResetFile();
COggData* theData = (COggData*)m_SoundData;
if (! theData->IsFileFinished())
{
int num_processed;
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
AL_CHECK
if (num_processed > 0)
{
ALuint* al_buf = new ALuint[num_processed];
alSourceUnqueueBuffers(m_ALSource, num_processed, al_buf);
AL_CHECK
int didWrite = theData->FetchDataIntoBuffer(num_processed, al_buf);
alSourceQueueBuffers(m_ALSource, didWrite, al_buf);
AL_CHECK
delete[] al_buf;
}
}
else if (GetLooping())
{
theData->ResetFile();
}
}
}
return true;
@ -95,7 +101,7 @@ bool CStreamItem::IdleTask()
void CStreamItem::Attach(CSoundData* itemData)
{
if (itemData != NULL)
if (itemData != NULL && (m_ALSource != 0) )
{
m_SoundData = itemData->IncrementCount();
alSourceQueueBuffers(m_ALSource, m_SoundData->GetBufferCount(), (const ALuint *)m_SoundData->GetBufferPtr());