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

Author Topic: sf::Text bug  (Read 3229 times)

0 Members and 3 Guests are viewing this topic.

Munvik

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
sf::Text bug
« on: December 18, 2016, 01:23:21 am »
Hi. Today i founded a bug.
When i use method setString() and as parameter use std::string wchich contains '8' or '=' those chars are deleting  :-\
It seems like sf::Text doesn't accept this chars. Someone know how could i fix it ?
« Last Edit: December 18, 2016, 02:03:14 am by Munvik »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
sf::Text bug
« Reply #1 on: December 18, 2016, 01:36:44 am »
Can you provide a complete and minimal example?

Also make sure to not mix release and debug builds.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Munvik

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: sf::Text bug
« Reply #2 on: December 18, 2016, 01:45:39 am »
sf::Text text;
/*
setting font, characterSize, color
*/

text.setString("80"); //showing 0
text.setString("82"); //showing 2
text.setString("808080"); //showing 000;

I tested it on my all sf::Text objects and result is the same :/

My build option is Release

Munvik

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: sf::Text bug
« Reply #3 on: December 18, 2016, 02:00:21 am »
And char '=' is bugged too, the same behavior  :-\

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: sf::Text bug
« Reply #4 on: December 18, 2016, 02:54:59 am »
i think you need to use std::to_string() if you want print a numbers as string.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
sf::Text bug
« Reply #5 on: December 18, 2016, 07:56:03 am »
It's not a complete example. Provide the code that you use and that you compile.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Munvik

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: sf::Text bug
« Reply #6 on: December 18, 2016, 12:55:48 pm »
So i have class wallet

class wallet :public sf::Drawable
{
        int gold;
        sf::Text goldText;
        sf::Sprite coin;
        sf::Texture coinTexture;

public:
        wallet();
        ~wallet();
        void draw(sf::RenderTarget & target, sf::RenderStates states) const;
        int getGold();
        bool isAfford(int amount);
        void pay(int amount);
        void setPosition(const sf::Vector2f position);

        sf::Vector2f getSize();
};

And in constructor i setText

goldText.setFont(*game::getInstance()->getFont());
goldText.setString("85");
goldText.setCharacterSize(30);
goldText.setColor(sf::Color(30, 40, 30));
goldText.setPosition(sf::Vector2f(100.f,20.f));

Here is the draw method

void wallet::draw(sf::RenderTarget & target, sf::RenderStates states) const
{
        target.draw(coin);
        target.draw(goldText);
}

When i draw wallet's object all is good except those chars

Munvik

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: sf::Text bug
« Reply #7 on: December 18, 2016, 12:58:57 pm »
i think you need to use std::to_string() if you want print a numbers as string.

Probably not, becouse other numbers works correctly :/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Text bug
« Reply #8 on: December 18, 2016, 01:10:00 pm »
Which font do you use?
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
sf::Text bug
« Reply #9 on: December 18, 2016, 01:12:02 pm »
You're still not showing the complete code as in SSCCE.

Aa a programmer you should learn to first search errors in your own code before trying to "blame" library code that is being used by hundreds of people. The best approaches to finding bugs is to make use of the debugger and to narrow down the problem until you're left with a SSCCE. If an issue can only be reproduced in the complex code setup, then it's a lot more likely that it's a problem in the user code.

Guesses I can make are:
Yiu used globally initialized SFML resources.
Or your font becomes invalid at one point.
Or you use a odd multi-threading setup.
Or you use a font with missing glyphs.

But without code, we can only make random guesses.
« Last Edit: December 18, 2016, 01:13:36 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Munvik

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: sf::Text bug
« Reply #10 on: December 18, 2016, 01:30:16 pm »
Yea my font Anorexia.ttf becomes invalid
I used impact.ttf and now it works  :D

Thanks for help.

 

anything