Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Text::getText Heap Crash  (Read 3448 times)

0 Members and 1 Guest are viewing this topic.

Ant

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
sf::Text::getText Heap Crash
« 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!

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: sf::Text::getText Heap Crash
« Reply #1 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.

Ant

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Re: sf::Text::getText Heap Crash
« Reply #2 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.

Ant

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Re: sf::Text::getText Heap Crash
« Reply #3 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.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: sf::Text::getText Heap Crash
« Reply #4 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
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

select_this

  • Full Member
  • ***
  • Posts: 130
  • Current mood: just ate a pinecone
    • View Profile
    • darrenferrie.com
Re: sf::Text::getText Heap Crash
« Reply #5 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 :)
Follow me on Twitter, why don'tcha? @select_this

 

anything