SFML community forums

Help => Audio => Topic started by: 4ian on August 13, 2012, 10:54:25 pm

Title: Crash when calling GetPlayingOffset with an uninitialized sf::Music
Post by: 4ian on August 13, 2012, 10:54:25 pm
Hi,

It seems that calling GetPlayingOffset on a uninitialized sf::Music lead to division by zero:

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

int main()
{
    sf::Music music;
    music.GetPlayingOffset(); //I'm using a revision of SFML2 before the changes in naming conventions.

    return EXIT_SUCCESS;

}

Here is the backtrace:
#0 627A06C1     __udivmoddi4(n=0, d=0) (../../../../src/gcc-4.5.2/libgcc/../gcc/libgcc2.c:895)
#1 ??   __udivdi3 (n=0, d=0) (../../../../src/gcc-4.5.2/libgcc/../gcc/libgcc2.c:1140)
#2 627898D3     sf::SoundStream::GetPlayingOffset(this=0x28feb8) (D:\Florian\Programmation\GameDevelop2\ExtLibs\SFML\src\SFML\Audio\SoundStream.cpp:174)
#3 004013B1     main() (D:\Florian\Programmation\SFML_test\main.cpp:7)

Looking at SoundStream::GetPlayingOffset, the line where the crash comes from is this one ( Maybe add a check to be sure that mySampleRate and myChannelsCount are not equal to 0) :
return seconds(secs + static_cast<float>(m_samplesProcessed) / m_sampleRate / m_channelCount);

( I'm not using the latest revision of SFML2, but this line is the same in the current revision as in the revision i'm using, so I believe the bug is still here. )
Title: Re: Crash when calling GetPlayingOffset with an uninitialized sf::Music
Post by: Laurent on August 13, 2012, 11:10:31 pm
I fixed it, thanks :)