1
Graphics / Drawing sf::Text results in a crash"writing_system_class" was nullptr
« on: September 07, 2021, 06:06:45 pm »
Hello,
I'm looking for some advice on how to use sf::Text object. Specifically what is causing this crash to occur from Freetype library. Right now, any attempts to draw sf::Text results in a crash. I have included a link to my source code below as well as screenshots that showcase my setup after a build/crash. I am running 64-bit Windows with vcpkg as my main source of pulling in dependencies. I'm more than certain I am using debug libraries for a DEBUG build as vs code cmake tools sets by default.
My Source Code
https://github.com/obscurelyme/hello-sfml/blob/ed15963b38b896e414fab1b811ac5c8c7918e92d/main.cpp#L53-L73
Code Snippet:
Here is the screenshot of the crash in debugger
I'm looking for some advice on how to use sf::Text object. Specifically what is causing this crash to occur from Freetype library. Right now, any attempts to draw sf::Text results in a crash. I have included a link to my source code below as well as screenshots that showcase my setup after a build/crash. I am running 64-bit Windows with vcpkg as my main source of pulling in dependencies. I'm more than certain I am using debug libraries for a DEBUG build as vs code cmake tools sets by default.
My Source Code
https://github.com/obscurelyme/hello-sfml/blob/ed15963b38b896e414fab1b811ac5c8c7918e92d/main.cpp#L53-L73
Code Snippet:
// Load fonts
std::string executableDirectory = std::filesystem::weakly_canonical(std::filesystem::path(argv[0])).parent_path().string();
std::string relativeFontFile = "/assets/fonts/Roboto/Roboto-Regular.ttf";
std::string fontFilePath = executableDirectory.append(relativeFontFile);
sf::Font font;
if (!font.loadFromFile(fontFilePath))
{
spdlog::debug("Could not load Roboto-Regular.ttf from directory {}", fontFilePath);
}
else
{
spdlog::debug("Successfully loaded {} font-family.", font.getInfo().family);
}
sf::Text text{"Hello", font, 48};
text.setFillColor(sf::Color::Red);
text.setStyle(sf::Text::Regular);
text.setPosition(200, 200);
...
while(running) {
sf::Event event;
while(window.pollEvent(event)) {
// handle event[s] ...
}
window.clear(sf::Color::Blue);
window.draw(text); // program crashes when this is called.
window.display();
}
std::string executableDirectory = std::filesystem::weakly_canonical(std::filesystem::path(argv[0])).parent_path().string();
std::string relativeFontFile = "/assets/fonts/Roboto/Roboto-Regular.ttf";
std::string fontFilePath = executableDirectory.append(relativeFontFile);
sf::Font font;
if (!font.loadFromFile(fontFilePath))
{
spdlog::debug("Could not load Roboto-Regular.ttf from directory {}", fontFilePath);
}
else
{
spdlog::debug("Successfully loaded {} font-family.", font.getInfo().family);
}
sf::Text text{"Hello", font, 48};
text.setFillColor(sf::Color::Red);
text.setStyle(sf::Text::Regular);
text.setPosition(200, 200);
...
while(running) {
sf::Event event;
while(window.pollEvent(event)) {
// handle event[s] ...
}
window.clear(sf::Color::Blue);
window.draw(text); // program crashes when this is called.
window.display();
}
Here is the screenshot of the crash in debugger