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:
parent
60987d46cf
commit
012e1585b1
@ -39,16 +39,19 @@ CBufferItem::~CBufferItem()
|
|||||||
AL_CHECK
|
AL_CHECK
|
||||||
|
|
||||||
Stop();
|
Stop();
|
||||||
int num_processed;
|
if (m_ALSource != 0)
|
||||||
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
|
|
||||||
|
|
||||||
if (num_processed > 0)
|
|
||||||
{
|
{
|
||||||
ALuint* al_buf = new ALuint[num_processed];
|
int num_processed;
|
||||||
alSourceUnqueueBuffers(m_ALSource, num_processed, al_buf);
|
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
|
||||||
|
|
||||||
AL_CHECK
|
if (num_processed > 0)
|
||||||
delete[] al_buf;
|
{
|
||||||
|
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()
|
bool CBufferItem::IdleTask()
|
||||||
{
|
{
|
||||||
HandleFade();
|
HandleFade();
|
||||||
|
if (m_ALSource != 0)
|
||||||
if (m_LastPlay)
|
|
||||||
{
|
{
|
||||||
int proc_state;
|
if (m_LastPlay)
|
||||||
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++)
|
|
||||||
{
|
{
|
||||||
ALuint al_buf;
|
int proc_state;
|
||||||
alSourceUnqueueBuffers(m_ALSource, 1, &al_buf);
|
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
|
||||||
AL_CHECK
|
|
||||||
alSourceQueueBuffers(m_ALSource, 1, &al_buf);
|
|
||||||
AL_CHECK
|
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)
|
void CBufferItem::Attach(CSoundData* itemData)
|
||||||
{
|
{
|
||||||
AL_CHECK
|
AL_CHECK
|
||||||
if (itemData != NULL)
|
if ( (itemData != NULL) && (m_ALSource != 0) )
|
||||||
{
|
{
|
||||||
m_SoundData = itemData->IncrementCount();
|
m_SoundData = itemData->IncrementCount();
|
||||||
alSourceQueueBuffers(m_ALSource, m_SoundData->GetBufferCount(),(const ALuint *) m_SoundData->GetBufferPtr());
|
alSourceQueueBuffers(m_ALSource, m_SoundData->GetBufferCount(),(const ALuint *) m_SoundData->GetBufferPtr());
|
||||||
|
@ -137,9 +137,7 @@ bool CSoundBase::InitOpenAL()
|
|||||||
{
|
{
|
||||||
alGetError(); /* clear error */
|
alGetError(); /* clear error */
|
||||||
alGenSources(1, &m_ALSource);
|
alGenSources(1, &m_ALSource);
|
||||||
long anErr = alGetError();
|
ALenum anErr = alGetError();
|
||||||
|
|
||||||
AL_CHECK
|
|
||||||
|
|
||||||
if (anErr == AL_NO_ERROR)
|
if (anErr == AL_NO_ERROR)
|
||||||
{
|
{
|
||||||
@ -160,9 +158,12 @@ bool CSoundBase::InitOpenAL()
|
|||||||
|
|
||||||
bool CSoundBase::IsPlaying()
|
bool CSoundBase::IsPlaying()
|
||||||
{
|
{
|
||||||
int proc_state;
|
ALenum proc_state = AL_STOPPED;
|
||||||
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
|
if ( m_ALSource != 0 )
|
||||||
AL_CHECK
|
{
|
||||||
|
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
|
||||||
|
AL_CHECK
|
||||||
|
}
|
||||||
|
|
||||||
return (proc_state == AL_PLAYING);
|
return (proc_state == AL_PLAYING);
|
||||||
}
|
}
|
||||||
@ -179,7 +180,7 @@ bool CSoundBase::IdleTask()
|
|||||||
|
|
||||||
void CSoundBase::SetLocation (const CVector3D& position)
|
void CSoundBase::SetLocation (const CVector3D& position)
|
||||||
{
|
{
|
||||||
if ( m_ALSource )
|
if ( m_ALSource != 0 )
|
||||||
{
|
{
|
||||||
alSourcefv(m_ALSource,AL_POSITION, position.GetFloatArray());
|
alSourcefv(m_ALSource,AL_POSITION, position.GetFloatArray());
|
||||||
AL_CHECK
|
AL_CHECK
|
||||||
@ -200,10 +201,11 @@ bool CSoundBase::HandleFade()
|
|||||||
Stop();
|
Stop();
|
||||||
else if (curGain == m_EndVolume)
|
else if (curGain == m_EndVolume)
|
||||||
{
|
{
|
||||||
alSourcef(m_ALSource, AL_GAIN, curGain);
|
if (m_ALSource != 0)
|
||||||
|
alSourcef(m_ALSource, AL_GAIN, curGain);
|
||||||
ResetFade();
|
ResetFade();
|
||||||
}
|
}
|
||||||
else
|
else if (m_ALSource != 0)
|
||||||
alSourcef(m_ALSource, AL_GAIN, curGain);
|
alSourcef(m_ALSource, AL_GAIN, curGain);
|
||||||
|
|
||||||
AL_CHECK
|
AL_CHECK
|
||||||
@ -219,8 +221,11 @@ bool CSoundBase::GetLooping()
|
|||||||
void CSoundBase::SetLooping(bool loops)
|
void CSoundBase::SetLooping(bool loops)
|
||||||
{
|
{
|
||||||
m_Looping = loops;
|
m_Looping = loops;
|
||||||
alSourcei(m_ALSource, AL_LOOPING, loops ? AL_TRUE : AL_FALSE);
|
if (m_ALSource != 0)
|
||||||
AL_CHECK
|
{
|
||||||
|
alSourcei(m_ALSource, AL_LOOPING, loops ? AL_TRUE : AL_FALSE);
|
||||||
|
AL_CHECK
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSoundBase::Play()
|
void CSoundBase::Play()
|
||||||
@ -261,16 +266,19 @@ void CSoundBase::PlayLoop()
|
|||||||
|
|
||||||
void CSoundBase::FadeToIn(ALfloat newVolume, double fadeDuration)
|
void CSoundBase::FadeToIn(ALfloat newVolume, double fadeDuration)
|
||||||
{
|
{
|
||||||
int proc_state;
|
if (m_ALSource != 0)
|
||||||
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
|
{
|
||||||
if (proc_state == AL_PLAYING)
|
ALenum proc_state;
|
||||||
{
|
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
|
||||||
m_StartFadeTime = timer_Time();
|
if (proc_state == AL_PLAYING)
|
||||||
m_EndFadeTime = m_StartFadeTime + fadeDuration;
|
{
|
||||||
alGetSourcef(m_ALSource, AL_GAIN, &m_StartVolume);
|
m_StartFadeTime = timer_Time();
|
||||||
m_EndVolume = newVolume;
|
m_EndFadeTime = m_StartFadeTime + fadeDuration;
|
||||||
|
alGetSourcef(m_ALSource, AL_GAIN, &m_StartVolume);
|
||||||
|
m_EndVolume = newVolume;
|
||||||
|
}
|
||||||
|
AL_CHECK
|
||||||
}
|
}
|
||||||
AL_CHECK
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSoundBase::PlayAsMusic()
|
void CSoundBase::PlayAsMusic()
|
||||||
|
@ -43,15 +43,19 @@ CSoundItem::~CSoundItem()
|
|||||||
AL_CHECK
|
AL_CHECK
|
||||||
|
|
||||||
Stop();
|
Stop();
|
||||||
alSourcei(m_ALSource, AL_BUFFER, 0);
|
|
||||||
AL_CHECK
|
if (m_ALSource != 0)
|
||||||
|
{
|
||||||
|
alSourcei(m_ALSource, AL_BUFFER, 0);
|
||||||
|
AL_CHECK
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSoundItem::IdleTask()
|
bool CSoundItem::IdleTask()
|
||||||
{
|
{
|
||||||
HandleFade();
|
HandleFade();
|
||||||
|
|
||||||
if (m_LastPlay)
|
if (m_LastPlay && (m_ALSource != 0) )
|
||||||
{
|
{
|
||||||
int proc_state;
|
int proc_state;
|
||||||
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
|
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
|
||||||
@ -63,7 +67,7 @@ bool CSoundItem::IdleTask()
|
|||||||
|
|
||||||
void CSoundItem::Attach(CSoundData* itemData)
|
void CSoundItem::Attach(CSoundData* itemData)
|
||||||
{
|
{
|
||||||
if (itemData != NULL)
|
if (itemData != NULL && (m_ALSource != 0) )
|
||||||
{
|
{
|
||||||
m_SoundData = itemData->IncrementCount();
|
m_SoundData = itemData->IncrementCount();
|
||||||
alSourcei(m_ALSource, AL_BUFFER, m_SoundData->GetBuffer());
|
alSourcei(m_ALSource, AL_BUFFER, m_SoundData->GetBuffer());
|
||||||
|
@ -36,16 +36,19 @@ CStreamItem::CStreamItem(CSoundData* sndData)
|
|||||||
CStreamItem::~CStreamItem()
|
CStreamItem::~CStreamItem()
|
||||||
{
|
{
|
||||||
Stop();
|
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];
|
int num_processed;
|
||||||
alSourceUnqueueBuffers(m_ALSource, num_processed, al_buf);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,39 +58,42 @@ bool CStreamItem::IdleTask()
|
|||||||
HandleFade();
|
HandleFade();
|
||||||
AL_CHECK
|
AL_CHECK
|
||||||
|
|
||||||
int proc_state;
|
if (m_ALSource != 0)
|
||||||
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
|
|
||||||
AL_CHECK
|
|
||||||
|
|
||||||
if (proc_state == AL_STOPPED)
|
|
||||||
{
|
{
|
||||||
if (m_LastPlay)
|
int proc_state;
|
||||||
return (proc_state != AL_STOPPED);
|
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
|
||||||
}
|
AL_CHECK
|
||||||
else if (m_SoundData != NULL)
|
|
||||||
{
|
|
||||||
COggData* theData = (COggData*)m_SoundData;
|
|
||||||
|
|
||||||
if (! theData->IsFileFinished())
|
if (proc_state == AL_STOPPED)
|
||||||
{
|
{
|
||||||
int num_processed;
|
if (m_LastPlay)
|
||||||
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
|
return (proc_state != AL_STOPPED);
|
||||||
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())
|
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;
|
return true;
|
||||||
@ -95,7 +101,7 @@ bool CStreamItem::IdleTask()
|
|||||||
|
|
||||||
void CStreamItem::Attach(CSoundData* itemData)
|
void CStreamItem::Attach(CSoundData* itemData)
|
||||||
{
|
{
|
||||||
if (itemData != NULL)
|
if (itemData != NULL && (m_ALSource != 0) )
|
||||||
{
|
{
|
||||||
m_SoundData = itemData->IncrementCount();
|
m_SoundData = itemData->IncrementCount();
|
||||||
alSourceQueueBuffers(m_ALSource, m_SoundData->GetBufferCount(), (const ALuint *)m_SoundData->GetBufferPtr());
|
alSourceQueueBuffers(m_ALSource, m_SoundData->GetBufferCount(), (const ALuint *)m_SoundData->GetBufferPtr());
|
||||||
|
Loading…
Reference in New Issue
Block a user