Fixed divide by zero when calling getPlayingOffset on an uninitialized sound stream

This commit is contained in:
Laurent Gomila 2012-08-13 23:11:27 +02:00
parent 1336a70eac
commit abd842510e

View File

@ -167,12 +167,19 @@ void SoundStream::setPlayingOffset(Time timeOffset)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Time SoundStream::getPlayingOffset() const Time SoundStream::getPlayingOffset() const
{
if (m_sampleRate && m_channelCount)
{ {
ALfloat secs = 0.f; ALfloat secs = 0.f;
alCheck(alGetSourcef(m_source, AL_SEC_OFFSET, &secs)); alCheck(alGetSourcef(m_source, AL_SEC_OFFSET, &secs));
return seconds(secs + static_cast<float>(m_samplesProcessed) / m_sampleRate / m_channelCount); return seconds(secs + static_cast<float>(m_samplesProcessed) / m_sampleRate / m_channelCount);
} }
else
{
return Time::Zero;
}
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////