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

Author Topic: Text setFont error  (Read 1960 times)

0 Members and 1 Guest are viewing this topic.

brother

  • Newbie
  • *
  • Posts: 3
    • View Profile
Text setFont error
« 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10913
    • View Profile
    • development blog
    • Email
AW: Text setFont error
« Reply #1 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

brother

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Text setFont error
« Reply #2 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10913
    • View Profile
    • development blog
    • Email
Re: Text setFont error
« Reply #3 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

brother

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Text setFont error
« Reply #4 on: August 19, 2016, 02:19:57 pm »
Thanks for reply!
Now everything is ok!

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