SFML community forums

Help => Audio => Topic started by: Entropy on July 18, 2014, 12:18:54 pm

Title: Heap Corruption Issue with sf::SoundBuffer::loadFromFile
Post by: Entropy on July 18, 2014, 12:18:54 pm
To get it out of the way, we're using the correct libraries already (Double checked for debug libs).

Now for some odd reason we've been having a heap corruption issue in our game, and I turned on page-heap safety thing with gflags todo some hardcore debugging of it, and it keeps popping back to..

        KernelBase.dll!_RaiseException@16()    Unknown
        [External Code]
        msvcr120d.dll!operator new(unsigned int size) Line 63   C++
        Game.exe!std::_Allocate<short>(unsigned int _Count, short * __formal) Line 28   C++
        Game.exe!std::allocator<short>::allocate(unsigned int _Count) Line 578  C++
        Game.exe!std::_Wrap_alloc<std::allocator<short> >::allocate(unsigned int _Count) Line 848       C++
        Game.exe!std::vector<short,std::allocator<short> >::_Reallocate(unsigned int _Count) Line 1588  C++
        Game.exe!std::vector<short,std::allocator<short> >::_Reserve(unsigned int _Count) Line 1619     C++
        Game.exe!std::vector<short,std::allocator<short> >::resize(unsigned int _Newsize) Line 1107     C++
        Game.exe!sf::SoundBuffer::initialize(sf::priv::SoundFile & file) Line 222       C++
>       Game.exe!sf::SoundBuffer::loadFromFile(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & filename) Line 84   C++
        Game.exe!ResourceSound::resolve() Line 53       C++

 

The last place it goes before all hell breaks loose in MSVCR is

SoundBuffer.cpp:222
    if (file.read(&m_samples[0], sampleCount) == sampleCount)

With params.
+               &m_samples      0x3d857fcc { size=0 }   std::vector<short,std::allocator<short> > *
+               file    {m_file=0x795badd0 {...} m_memory={begin=0xcccccccc <Error reading characters of string.> current=0xcccccccc <Error reading characters of string.> ...} ...}    sf::priv::SoundFile &
+               m_samples       { size=0 }      std::vector<short,std::allocator<short> >
                sampleCount     357554  unsigned int
+               this    0x3d857fc8 {m_buffer=938442712 m_samples={ size=0 } m_duration={m_microseconds=0 } ...} sf::SoundBuffer *

 

Title: Re: Heap Corruption Issue with sf::SoundBuffer::loadFromFile
Post by: Laurent on July 18, 2014, 12:22:57 pm
http://sscce.org/
Title: Re: Heap Corruption Issue with sf::SoundBuffer::loadFromFile
Post by: Entropy on July 18, 2014, 12:31:01 pm
I can't give you a self contained sample because its part of the entire game.
Title: Re: Heap Corruption Issue with sf::SoundBuffer::loadFromFile
Post by: binary1248 on July 18, 2014, 12:37:03 pm
its part of the entire game.
There's your problem ;). How can we be sure this is caused by SFML if you can't isolate the problem? We have to assume that SFML is caused to crash by your code if this only happens within that context.

Also... I don't think it is that hard to come up with some form of mock up of the code used in your game within a separate project. It doesn't have to be a 1:1 copy, but has to use SFML in the same way (make the same API calls, possibly with the same data) as your game does.
Title: Re: Heap Corruption Issue with sf::SoundBuffer::loadFromFile
Post by: Laurent on July 18, 2014, 01:34:53 pm
Quote
I can't give you a self contained sample because its part of the entire game.
I think you misunderstood what a SSCCE is. This page exists for people like you, with a big project and a bug inside. We don't expect you to already have a simple code ready to be posted on forums, we expect you to write it. And this page explains how to do it.

If you fail to isolate the bug from your entire game, then it means that it is caused by complex interactions between your game classes. And this is something that nobody but you can debug.