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

Author Topic: Font or Text render exception  (Read 5677 times)

0 Members and 2 Guests are viewing this topic.

Filosof

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Font or Text render exception
« on: November 16, 2021, 08:26:44 pm »
Some strange exception are always thrown on Windows 10.
"Access violation reading location ".
I reduced it to problem code. Everything else, including graphics, sprites, music - working. All libraries are included. But once I put "window.draw(text)" - > I get this exception. It worth noticed that same project is working on Linux. But Windows got some issue.
Please help.
Source code:

#include <SFML/Graphics.hpp>
int main()
{
  sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

  sf::Font font;
  if (!font.loadFromFile("C:/Users/user/source/repos/BattleCity2/media/arial.ttf"))
    return EXIT_FAILURE;

  sf::Text text("Hello SFML", font, 50);

  while (window.isOpen())
  {
    sf::Event event;
    while (window.pollEvent(event))
    {
      if (event.type == sf::Event::Closed)
        window.close();
    }
    window.clear();
    window.draw(text);
    window.display();
  }
  return EXIT_SUCCESS;
}
 

Call stack:
BattleCity2.exe!af_shaper_get_elem()
BattleCity2.exe!af_shaper_get_elem()
BattleCity2.exe!af_shaper_get_elem()
BattleCity2.exe!FT_Load_Glyph()
BattleCity2.exe!FT_Load_Char()
BattleCity2.exe!sf::Font::loadGlyph(unsigned int,unsigned int,bool,float)
BattleCity2.exe!sf::Font::getGlyph(unsigned int,unsigned int,bool,float)
BattleCity2.exe!sf::Text::ensureGeometryUpdate(void)
BattleCity2.exe!sf::Text::draw(class sf::RenderTarget &,class sf::RenderStates)
BattleCity2.exe!sf::RenderTarget::draw(class sf::Drawable const &,class sf::RenderStates const &)
BattleCity2.exe!main() Line 22

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Font or Text render exception
« Reply #1 on: November 16, 2021, 09:54:51 pm »
Are you linking release libraries in debug mode? (linking sfml-graphics.lib instead of sfml-graphics-d.lib)

Filosof

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: Font or Text render exception
« Reply #2 on: November 17, 2021, 04:03:57 pm »
Are you linking release libraries in debug mode? (linking sfml-graphics.lib instead of sfml-graphics-d.lib)

It is a good question. I build my project on CMake and get libraries from Conan.
Is there any way to distinguish release and debug package from conan?
Right now it is like:

conan_cmake_run(
            REQUIRES
            imgui-sfml/2.1@bincrafters/stable
            BUILD
            missing
    )

...

target_link_libraries(
        ${PROJECT_NAME}
        CONAN_PKG::imgui-sfml
)
I doubt if building CMake with release option will link right library. No?
« Last Edit: November 17, 2021, 04:08:00 pm by Filosof »

Filosof

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: Font or Text render exception
« Reply #3 on: November 18, 2021, 10:45:37 am »
Update:
  • I have managed to build project with Conan release settings. Unfortunately it didn't help for Win10. On Ubuntu everything works both on debug and release build.
  • sf::Glyph glyph = font.getGlyph('A', 20u, false); <- produce same exception.

« Last Edit: November 18, 2021, 05:08:48 pm by Filosof »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Font or Text render exception
« Reply #4 on: November 19, 2021, 09:40:01 am »
The conan bit you showed was for imgui-sfml, do you also get SFML that way? Which package are you using?
Is Conan providing freetype as part of the SFML package or as a separate package?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Filosof

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: Font or Text render exception
« Reply #5 on: November 19, 2021, 07:06:00 pm »
The conan bit you showed was for imgui-sfml, do you also get SFML that way? Which package are you using?
Is Conan providing freetype as part of the SFML package or as a separate package?

Yes you are right. Updated Conan for correct library.
conan_cmake_run(
            REQUIRES
            sfml/2.5.1
            OPTIONS
            BASIC_SETUP
            CMAKE_TARGETS
            BUILD
            missing
    )
I see it links following libs:
sfml-audio-s-d.lib
sfml-graphics-s-d.lib
sfml-main-d.lib
sfml-network-s-d.lib
sfml-system-s-d.lib
sfml-window-s-d.lib

Conan: Settings= -s;arch=x86_64;-s;build_type=Debug;-s;compiler=Visual Studio;-s;compiler.version=16;-s;compiler.runtime=MDd

But still get same exception on Win10.
« Last Edit: November 19, 2021, 07:14:21 pm by Filosof »

 

anything