From f9233e792b0e42e9492a55a7aa40f8e7891d6085 Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Tue, 25 Mar 2014 22:01:07 +0100 Subject: [PATCH] Output error message in SoundStream when bits are zero Fixes #529 --- src/SFML/Audio/SoundStream.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index bf055718..972bdbf9 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -85,7 +85,7 @@ void SoundStream::play() // Check if the sound parameters have been set if (m_format == 0) { - err() << "Failed to play audio stream: sound parameters have not been initialized (call Initialize first)" << std::endl; + err() << "Failed to play audio stream: sound parameters have not been initialized (call initialize() first)" << std::endl; return; } @@ -258,7 +258,22 @@ void SoundStream::streamData() ALint size, bits; alCheck(alGetBufferi(buffer, AL_SIZE, &size)); alCheck(alGetBufferi(buffer, AL_BITS, &bits)); - m_samplesProcessed += size / (bits / 8); + + // Bits can be 0 if the format or parameters are corrupt, avoid division by zero + if (bits == 0) + { + err() << "Bits in sound stream are 0: make sure that the audio format is not corrupt " + << "and initialize() has been called correctly" << std::endl; + + // Abort streaming (exit main loop) + m_isStreaming = false; + requestStop = true; + break; + } + else + { + m_samplesProcessed += size / (bits / 8); + } } // Fill it and push it back into the playing queue