SFML community forums

Help => Graphics => Topic started by: Ant on July 17, 2014, 05:57:04 am

Title: sf::Text::getText Heap Crash
Post by: Ant on July 17, 2014, 05:57:04 am
Hello,

I've spent the last few days investigating this crash, but I'm finding myself traveling in circles now.
I'm running into a heap crash when I call sf::Text::getText()
std::string stdString = text.getString();

Here's the crash message I'm running into:
Quote
Program: ...s\visual studio 2013\Projects\TextTest\x64\Debug\TextTest.exe
File: f:\dd\vctools\crt\crtw32\misc\dbgheap.c
Line: 1424

Expression: _pFirstBlock == pHead

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)

I'm using Visual Studio 2013 Express.
This crash only occurs in debug.
This happens in 32bit and 64bit.
I'm using the latest stable version SFML 2.1 for Visual Studio 2012 64bit.


#include <SFML/Graphics.hpp>

int main()
{
        sf::Font font;
        if (!font.loadFromFile("TheanoModern-Regular.ttf"))
        {
                return 0;
        }

    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");

        sf::Text text;
       
        text.setFont(font);
        text.setString(L"Hello World.\0");
        std::string stdString = text.getString(); //crashes here

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(text);
        window.display();
    }

    return 0;
}

Let me know if you need any further information.
Thank you in advance for your help!
Title: Re: sf::Text::getText Heap Crash
Post by: Jesper Juhl on July 17, 2014, 07:45:42 am
If you are using VS2013 together with a copy of SFML built with/for a different VS version then that explains it perfectly.
Either use the VS version that SFML was built for or recompile SFML with your current VS.
Title: Re: sf::Text::getText Heap Crash
Post by: Ant on July 18, 2014, 08:07:33 am
That's one of the problems I've suspected earlier.  A couple days ago, I've compiled SFML using CMake, and I was still running into this heap crash.  I've decided to post about my attempt in using the stable version to reduce the number of variables.


Today, I've started over in case I've done something wrong last time I've compiled SFML.  I'm not sure what I have done wrong last time, but I'm relieved to find out that I was able to launch my TextTest solution in debug mode.

My main project is still encountering the heap crash, but I haven't done enough investigation to find the culprit.  I'll continue tomorrow.
Title: Re: sf::Text::getText Heap Crash
Post by: Ant on July 19, 2014, 06:19:27 am
Although I'm happy that I've found the solution, I'm also disappointed that it was something minor.  Here's what my configuration manager looked like when I've revisited it.  My Release build was correct, but Debug was not set correctly (see attachment in what I saw).

I apologies for the false alarm.
Title: Re: sf::Text::getText Heap Crash
Post by: zsbzsb on July 19, 2014, 02:10:32 pm
Don't worry about it  ;)  This is a common mistake that many have made, so do not put yourself down over this. Instead learn from it and do not make the same mistake again.  :D
Title: Re: sf::Text::getText Heap Crash
Post by: select_this on July 19, 2014, 07:35:16 pm
And if you do make the same mistake again, or a similar one, you'll have a headstart on how to solve it :)