Fixed soundbuffer contents not being able to be updated when still attached to sounds (#354), sounds now detach from their buffer when it is reset. Signed-off-by: binary1248 <binary1248@hotmail.com>
This commit is contained in:
parent
e6b5ce1f27
commit
0375d7588f
@ -189,8 +189,12 @@ void Sound::resetBuffer()
|
||||
stop();
|
||||
|
||||
// Detach the buffer
|
||||
if (m_buffer)
|
||||
{
|
||||
alCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||
m_buffer->detachSound(this);
|
||||
m_buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
@ -248,6 +248,13 @@ bool SoundBuffer::update(unsigned int channelCount, unsigned int sampleRate)
|
||||
return false;
|
||||
}
|
||||
|
||||
// First make a copy of the list of sounds so we can reattach later
|
||||
SoundList sounds(m_sounds);
|
||||
|
||||
// Detach the buffer from the sounds that use it (to avoid OpenAL errors)
|
||||
for (SoundList::const_iterator it = sounds.begin(); it != sounds.end(); ++it)
|
||||
(*it)->resetBuffer();
|
||||
|
||||
// Fill the buffer
|
||||
ALsizei size = static_cast<ALsizei>(m_samples.size()) * sizeof(Int16);
|
||||
alCheck(alBufferData(m_buffer, format, &m_samples[0], size, sampleRate));
|
||||
@ -255,6 +262,10 @@ bool SoundBuffer::update(unsigned int channelCount, unsigned int sampleRate)
|
||||
// Compute the duration
|
||||
m_duration = seconds(static_cast<float>(m_samples.size()) / sampleRate / channelCount);
|
||||
|
||||
// Now reattach the buffer to the sounds that use it
|
||||
for (SoundList::const_iterator it = sounds.begin(); it != sounds.end(); ++it)
|
||||
(*it)->setBuffer(*this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user