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:
Joshua Adam Reisenauer 2014-05-01 02:09:12 +02:00 committed by Lukas Dürrenberger
parent e6b5ce1f27
commit 0375d7588f
2 changed files with 17 additions and 2 deletions

View File

@ -189,8 +189,12 @@ void Sound::resetBuffer()
stop();
// Detach the buffer
alCheck(alSourcei(m_source, AL_BUFFER, 0));
m_buffer = NULL;
if (m_buffer)
{
alCheck(alSourcei(m_source, AL_BUFFER, 0));
m_buffer->detachSound(this);
m_buffer = NULL;
}
}
} // namespace sf

View File

@ -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;
}