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();
|
stop();
|
||||||
|
|
||||||
// Detach the buffer
|
// Detach the buffer
|
||||||
alCheck(alSourcei(m_source, AL_BUFFER, 0));
|
if (m_buffer)
|
||||||
m_buffer = NULL;
|
{
|
||||||
|
alCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||||
|
m_buffer->detachSound(this);
|
||||||
|
m_buffer = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
@ -248,6 +248,13 @@ bool SoundBuffer::update(unsigned int channelCount, unsigned int sampleRate)
|
|||||||
return false;
|
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
|
// Fill the buffer
|
||||||
ALsizei size = static_cast<ALsizei>(m_samples.size()) * sizeof(Int16);
|
ALsizei size = static_cast<ALsizei>(m_samples.size()) * sizeof(Int16);
|
||||||
alCheck(alBufferData(m_buffer, format, &m_samples[0], size, sampleRate));
|
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
|
// Compute the duration
|
||||||
m_duration = seconds(static_cast<float>(m_samples.size()) / sampleRate / channelCount);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user