SFML community forums

Help => Graphics => Topic started by: brother on August 19, 2016, 11:12:11 am

Title: Text setFont error
Post by: brother on August 19, 2016, 11:12:11 am
Hello!

I'm using Visual Studio express 2013 + SFML 2.4.0 for vc12 32-bit.

Here goes problem code:

sf::Font font;
if (!font.loadFromFile("res/Calibri.ttf")) {
        std::cout << "Font load error" << std::endl;
        return;
} else {
        std::cout << "Font no error" << std::endl;
}

m_input.setFont(font);
 

Font is loading with no errors!
But i got exception on m_input.setFont(font).

I've put error message and my additional dependencies screenshots at atachments.

Any clues?
Title: AW: Text setFont error
Post by: eXpl0it3r on August 19, 2016, 12:12:51 pm
Are those libraries in debug mode? Are you running your application in debug mode? What's the call stack?
Title: Re: Text setFont error
Post by: brother on August 19, 2016, 12:52:18 pm
I'm running in debug mode.

I've attached call stack screenshot.

Seems that problem is here:

void Console::Render(sf::RenderWindow& window)
{
        window.draw(m_background);
        window.draw(m_input);
}
 

On window.draw(m_input) i've got:
Frames below may be incorrect and / or missing, no symbols loaded for sfml-grahpics-d-2.dll
Title: Re: Text setFont error
Post by: eXpl0it3r on August 19, 2016, 12:55:23 pm
So it doesn't crash where you said it was crashing. ;)

Since we don't know the full code, my guess is that you load the font locally (no member variable), then set the reference to the font for the text object and the leave the function which destroys the font object, leaving the text object with a reference into no where.

Font objects need to exist as long as they are used by text objects.
Title: Re: Text setFont error
Post by: brother on August 19, 2016, 02:19:57 pm
Thanks for reply!
Now everything is ok!

I'm newbie to c++, sorry for disturbing you.