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

Author Topic: sf::Font generates strange behaviour  (Read 769 times)

0 Members and 1 Guest are viewing this topic.

Ullaakut

  • Newbie
  • *
  • Posts: 6
    • View Profile
sf::Font generates strange behaviour
« on: June 22, 2015, 01:03:44 pm »
Hi,

I'm having issues with sf::Font and sf::Text instances.

My Interface class contains an instance of sf::Font, and at each loop turn, I instantiate an sf::Text using my previously loaded font. The problem is that even though the loading seems to work correctly, my game doesn't work and hangs in the networking part of my game loop.

If I comment the lines where the font is loaded, the problem disappears.. I can't figure out what could be the problem.

Here is my Interface class :

#include "Interface.hh"

Interface::Interface()
{
        if (!_font.loadFromFile(FONT))
           std::cerr << "Font loading failed" << std::endl;
}

Interface::~Interface() {}

void Interface::update(std::map<AObject::Objects, int> c)
{
        this->_content = c;
}

void Interface::draw(sf::RenderWindow *w, std::map<AObject::Objects, sf::Texture>& t, Team* team)
{
        sf::Sprite s;
        if (team != nullptr)
                {
                        sf::Text text(team->getId(), _font, 150);

                        text.setPosition(915, 380);
                        text.setColor(team->getColor());
                        text.setStyle(sf::Text::Regular);
                        w->draw(text);
                }
        s.setTexture(t[AObject::INTERFACE]);
        s.setPosition(900, 0);
        w->draw(s);
}
 

Everything works absolutely fine without the use of sf::Font and sf::Text in this part of the code.

Am I missing something obvious here? :/

EDIT: Valgrind seems to correct the strange behaviour but doesn't tell me where it happens

REEDIT: Problem solved, apparently an error in my Networking class was not causing any trouble before, but does when instantiating a sf::Font. The error has been deleted, and everything runs fine now. Sorry for the trouble :) This post can be deleted, it won't help anyone

Thanks
« Last Edit: June 22, 2015, 01:26:15 pm by Ullaakut »

Hapax

  • Hero Member
  • *****
  • Posts: 3058
  • My number of posts is shown in hexadecimal.
    • View Profile
Re: sf::Font generates strange behaviour
« Reply #1 on: June 23, 2015, 01:42:32 am »
Problem solved, apparently an error in my Networking class was not causing any trouble before, but does when instantiating a sf::Font. The error has been deleted, and everything runs fine now. [...] This post can be deleted, it won't help anyone
It you could post what you were doing that actually caused the issue to start with, this may very well help someone in the future who has the same issue.
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

@Hapaxiation - Hapaxia on Twitter

 

anything