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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - AlexBratosin

Pages: [1]
1
Graphics / Re: sf::Text::Font pointers reset to NULL
« on: August 22, 2017, 02:16:24 pm »
Thanks for replying Laurent!
That cleared it up.

2
Graphics / sf::Text::Font pointers reset to NULL
« on: August 21, 2017, 11:59:11 pm »
Hey people!

I'm trying to understand why I keep getting an access violation while drawing a sf::Text.
I've managed to replicate my current scenario in the code below.
Basically, in that for loop, the pointers of the font present in a.text (m_library...) are set correctly but after the first iteration if I go ahead and check objects[0].text, those pointers are reset to NULL.
Could you please explain to me this behavior?

Thanks a lot!

Note: please ignore the ugliness of this code as it's only meant for demonstration purposes :)

class myClass
{
public:
        sf::Text text;
        sf::Font font;
};

void main()
{
        std::vector<myClass> objects;
        sf::Font f;
        f.loadFromFile("arial.ttf");
        for (int i = 0; i < 10; i++)
        {
                myClass a;
                a.font = f;
                a.text.setFont(a.font);
                objects.push_back(a);
        }
        sf::RenderWindow window(VideoMode(100, 100), "window");
        while (window.isOpen())
        {
                window.clear();
                for (myClass a : objects)
                {
                        window.draw(a.text);
                }
                window.display();
        }
}
 

Pages: [1]