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

Author Topic: [SOLVED] sf::Text setString() causing segfault (symbol not found)  (Read 2865 times)

0 Members and 2 Guests are viewing this topic.

Artexflow

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Hi everyone,

I'm experiencing a strange behavior on SFML 2.3.2 with Visual Studio 14. I'm using the precompiled library that can be found here : http://www.sfml-dev.org/download/sfml/2.3.2/
I'm using the debug dlls.

The symptom is a segfault when I try to use the member function setString on an sf::Text object.

Useful infos :
    - _statsString is an attribute of the Application class ;
    - I'm mixing SFML and openGL calls ;
    - this is part of a game engine (some of you may recognize some things from the SFML Game Dev book - great book !).

Here are the most relevant parts of the code :

In the Application constructor, where I load my font and set some options of _statsString :
Application::Application() :
    ...
{  
        if (!_statsFont.loadFromFile("Sansation.ttf"))
                throw std::runtime_error("Error loading statistics font");
        _statsString.setFont(_statsFont);
        _statsString.setPosition(5.f, 5.f);
        _statsString.setCharacterSize(10);
}
 

When the segfault occurs :
void    Application::_updateStats(sf::Time dt)
{
        _statsUpdateTime += dt;
        _statsFrameCount += 1;

        if (_statsUpdateTime >= sf::seconds(1.0f))
        {
                _statsString.setFont(_statsFont);
                _statsString.setString("FPS: " + std::to_string(_statsFrameCount)); // <- Oh damn.
                _statsUpdateTime -= sf::seconds(1.0f);
                _statsFrameCount = 0;
        }
}

Visual's debugger is telling me that _statsString is a symbol not found, which is strange cause any other method seems to work properly...

Last but not least, under the MSYS2 toolchain (msys2 + mingw-w64) and with the 2.3.1 which I compiled myself, this bug does not occur.

Anyone has a clue on what's happening ?
Thanks a lot !
« Last Edit: October 31, 2015, 04:47:40 am by Artexflow »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: sf::Text setString() causing segfault (symbol not found)
« Reply #1 on: October 29, 2015, 08:57:22 pm »
Hi everyone,

I'm experiencing a strange behavior on SFML 2.3.2 with Visual Studio 14. I'm using the precompiled library that can be found here : http://www.sfml-dev.org/download/sfml/2.3.2/
There are many different builds available there. Which one are you using?
I didn't know that Visual Studio 2014 was a thing. 2013, 2015 sure. But 2014? What's that?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Text setString() causing segfault (symbol not found)
« Reply #2 on: October 29, 2015, 09:01:04 pm »
I didn't know that Visual Studio 2014 was a thing. 2013, 2015 sure. But 2014? What's that?
14 != 2014

https://en.wikipedia.org/wiki/Microsoft_Visual_Studio#History
Yes, it is confusing ;)

And note how they skipped the 13. I can't believe that superstition is still that omnipresent in 2015, especially among developers ::)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: sf::Text setString() causing segfault (symbol not found)
« Reply #3 on: October 29, 2015, 09:28:35 pm »
That's just fscked up and weird for no good reason. :-/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Text setString() causing segfault (symbol not found)
« Reply #4 on: October 29, 2015, 09:52:34 pm »
No, it's not.

The problem is that people think the year (2015) denotes the version, but it does not. It's only part of the product name and describes when the product was released. This is not even something rarely seen in marketing.

There are good reasons to keep a separate version number -- it is strictly monotonic and independent of product naming schemes. For example, you see that early VS releases didn't follow this scheme. This happens in many products, not just Visual Studio. The only reason why it's confusing here is that the last two digits of the year are in the same range as the IDE's version number.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: sf::Text setString() causing segfault (symbol not found)
« Reply #5 on: October 29, 2015, 09:54:48 pm »
I guess I just have to read up on VS version numbers then.
But yes, a monotonic increasing version independant of product release year does make sense.

Artexflow

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: sf::Text setString() causing segfault (symbol not found)
« Reply #6 on: October 29, 2015, 11:29:24 pm »
Yep VS version numbers are hard to get :)

Btw, I've managed to get rid of that segfault by compiling myself and using the 2.3.1 version of SFML. You could guess it's a good news - and it is, but now I've got another problem.
As you can see on the upper left corner of my screenshot, the text does not draw letters, but instead... rectangles.



Any ideas on what could be causing this and how to fix it ?

Code concerning text has not been changed.

Update :
That rectangle seems to be linked to a texture. Here is what happens when I use another texture :


When I unbind it or disable it on OpenGL it stays the same.

glBindTexture(GL_TEXTURE_2D, 0);
or
glDisable(GL_TEXTURE_2D);
 

When I don't load any texture on OpenGL, I have a white rectangle.
If I set the font color using setColor(), my texture just turns to the text color I've just set.


Thanks !
« Last Edit: October 30, 2015, 01:27:26 am by Artexflow »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Did you follow the OpenGL tutorial for SFML? You need to save & restore SFML's states if you mix it with your own OpenGL code.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Artexflow

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Hi ! Thanks for your answer :)

Of course ! States are pushed and popped like they should be.
I've managed to solve my problem, and it was quite dumb, I was using some SFML libraries in debug mode, and some other in release mode...

Now everything works like a charm !