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 (https://github.com/obscurelyme/hello-sfml)
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();
}
(https://raw.githubusercontent.com/obscurelyme/hello-sfml/master/doc/debug-libs-screenshot.PNG)
Here is the screenshot of the crash in debugger
(https://raw.githubusercontent.com/obscurelyme/hello-sfml/master/doc/stack-screenshot.PNG)
May I ask how you did this? For me it won't work.
I edited the vcpkg.json in the ports\sfml dir to
{
"name": "sfml",
"version": "2.5.1",
"port-version": 10,
"description": "Simple and fast multimedia library",
"homepage": "https://github.com/sfml/sfml",
"dependencies": [
"freetype",
"libflac",
"libogg",
"libvorbis",
"openal-soft",
"stb"
],
"builtin-baseline":"92af1ff59a651c1cf43aca48f54369a86d40d81c",
"overrides":[{"name":"sfml", "version":"2.10.0"}]
}
I got the value of builtin-baseline by doing
git rev-parse HEAD
This didn't do anything for me: it still grabbed freetype version 2.11.0.
Then I edited vcpkg\versions\baseline.json and changed the baseline of freetype to 2.10.0 and I edited the vcpkg.json of freetype to also take 2.10.0:
"version-semver": "2.10.0",
Now it SAYS that it takes 2.10.0. And vcpkg list says 2.10.0 for freetype. But the dll version is STILL 2.11.0 and drawing an sf::Text STILL crashes in freetype.
Maybe the easier way is to compile sfml with cmake and copy the freetype dll into the vcpkg\bin dir