From abd842510efaa2816b2f2e7348426163c57058c5 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Mon, 13 Aug 2012 23:11:27 +0200 Subject: [PATCH] Fixed divide by zero when calling getPlayingOffset on an uninitialized sound stream --- src/SFML/Audio/SoundStream.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index 4b2f2d4f..4b2eff3d 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -168,10 +168,17 @@ void SoundStream::setPlayingOffset(Time timeOffset) //////////////////////////////////////////////////////////// Time SoundStream::getPlayingOffset() const { - ALfloat secs = 0.f; - alCheck(alGetSourcef(m_source, AL_SEC_OFFSET, &secs)); + if (m_sampleRate && m_channelCount) + { + ALfloat secs = 0.f; + alCheck(alGetSourcef(m_source, AL_SEC_OFFSET, &secs)); - return seconds(secs + static_cast(m_samplesProcessed) / m_sampleRate / m_channelCount); + return seconds(secs + static_cast(m_samplesProcessed) / m_sampleRate / m_channelCount); + } + else + { + return Time::Zero; + } }