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

Author Topic: Font issues  (Read 1609 times)

0 Members and 1 Guest are viewing this topic.

Rodax

  • Newbie
  • *
  • Posts: 3
    • View Profile
Font issues
« on: November 11, 2011, 05:53:00 am »
After a certain point in my program, nothing having to do with fonts will display. Is there something wrong with my code? I've changed it in all sorts of ways and nothing seems to solve the problem.

Code: [Select]
void Atom::Draw(sf::RenderWindow& Disp,sf::Font& Font,int x,int y)
{
    this->x = x;
    this->y = y;
    this->h = Bmp.GetRect().GetHeight();
    this->w = Bmp.GetRect().GetWidth();

    Bmp.SetText(Label.c_str());
    Bmp.SetFont(Font);
    Bmp.SetSize(28);
    Bmp.SetColor(CurrentColor);

    if (!Unstable)
    {
        Bmp.Move(x,y);
        Disp.Draw(Bmp);
    }


And here in a thread func.

Code: [Select]
void Loading(void* UserData)
{
    vector<sf::String> LoadingVector;

    sf::Color White;
    White.r = 255;
    White.g = 255;
    White.b = 255;
    White.a = 255;

    sf::String loads("Loading",sf::Font::GetDefaultFont(),48);
    sf::String loads1("Loading.",sf::Font::GetDefaultFont(),48);
    sf::String loads2("Loading..",sf::Font::GetDefaultFont(),48);
    sf::String loads3("Loading...",sf::Font::GetDefaultFont(),48);

    LoadingVector.push_back(loads);
    LoadingVector.push_back(loads1);
    LoadingVector.push_back(loads2);
    LoadingVector.push_back(loads3);

    for (unsigned int o=0;o<LoadingVector.size();o++)
    {
        LoadingVector[o].SetColor(White);
        LoadingVector[o].SetStyle(sf::String::Bold);
    }

    unsigned int i=0;

    long now = time(NULL);
    long then = now + 5;

    while(now < then)
    {
        UWin.Clear(sf::Color(70,255,100));

        int cx,cy;
        cx = (640 - LoadingVector[i].GetRect().GetWidth())/2;
        cy = (480 - LoadingVector[i].GetRect().GetHeight())/2;

        LoadingVector[i].Move(cx,cy);
        UWin.Draw(LoadingVector[i]);

        UWin.Display();
        Delay(400);

        i++;
        if (i > LoadingVector.size()-1)
            i = 0;

        time(&now);
    }

    LoadingVector.clear();

    UWin.Clear();
    UWin.Display();
}
I mean well. Promise. It just doesn't sound like it.

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Font issues
« Reply #1 on: November 11, 2011, 11:15:10 am »
It could be that you are not activating the window for your current thread.

Make sure that when you are going to render in a thread, you call myWindow.SetActive(false) to deactivate in the previous thread, and myWindow.SetActive(true) in the new thread.

See Window.hpp for more info.
SFML 2.1

Rodax

  • Newbie
  • *
  • Posts: 3
    • View Profile
Font issues
« Reply #2 on: November 11, 2011, 06:52:18 pm »
Wow that's pretty interesting. Thanks. That fixed it for the thread, but now it completely crashes after it (the other posted code).

EDIT:: Doesn't crash anymore, however, now it only draws the font on the first frame. Never again.
I mean well. Promise. It just doesn't sound like it.

luiscubal

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Font issues
« Reply #3 on: November 11, 2011, 07:04:21 pm »
Make sure all of your shared resources remain in scope while the side thread is running.
One easy way to ensure this is to make your shared resources global variables.

Because if your code tries to use a variable that goes out of scope(e.g. is used after being destroyed), that'd be a memory corruption bug, which can indeed cause crashes and unexpected behavior.

Rodax

  • Newbie
  • *
  • Posts: 3
    • View Profile
Font issues
« Reply #4 on: November 11, 2011, 07:50:55 pm »
It seems to be crashing when the Atom constructor runs (if commented, it doesn't crash). The atom class has an sf::String member that is given a font reference to keep until it is drawn with a member function. The font itself is global already
I mean well. Promise. It just doesn't sound like it.