Sfml: Memory leak when sf::Text::setOutlineThickness is used

Created on 22 May 2017  路  3Comments  路  Source: SFML/SFML

Seems to be that Font.cpp - line 561 creates a leak as indicated by this answer on StackOverflow:
https://stackoverflow.com/a/44074908/5044558
Followed by a discussion on the sfml-dev forums:
https://en.sfml-dev.org/forums/index.php?topic=21996.0

Working with SFML 2.4.2 on Windows 7 64-bit version, I've noticed an issue with sf::Text::setOutlineThickness(float). Once it is used in the program, except for default value 0, crtdbg dumps a memory leak of various sizes of bytes but always the same amount. I believe this is related to the size of the string, if the text gets drawn, and if the parameter of setOutlineThickness is accepted, demonstrated here:

/// Initial set-up
sf::Text test;
test.setString("A");
// ... Set charactersize, font, fillcolor, etc ...
test.setOutlineThickness(1);
test.setOutlineColor(sf::Color::Black);

/// Make a drawcall for test later in the program
void Game::draw(sf::RenderTarget & target, sf::RenderStates states) const
{
    target.draw(test, states);
}

If the line in Font.cpp is modified to,
FT_Glyph_Stroke(&glyphDesc, stroker, true);
Then there are no memory leaks and the program can still display the text without problems. This was tested on SFML's source code from the master branch and was built in Win32 debug and release.

bug sfml-graphics accepted

Most helpful comment

Funny I was just looking into this as well. Related to #1313 I will try to fix them together.

All 3 comments

The leak seems to originate exactly from this line, because if argument is set to "false", then the memory allocated to glyphDesc before FT_Glyph_Stroke(...) call will be hanging, because after the call glyphDesc is redirected to a newly allocated memory, which stores modified glyph. This new memory will be cleared with FT_Done_Glyph(glyphDesc) at the end, but the old allocated memory isn't referenced to anymore.
Slightly more details on the forums
https://en.sfml-dev.org/forums/index.php?topic=21996.msg156356#msg156356

Funny I was just looking into this as well. Related to #1313 I will try to fix them together.

Fixed with #1360 and merged in d972216c57e2fe28fd36dad55c0772078640e971

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fxcoudert picture fxcoudert  路  7Comments

exitc0d3 picture exitc0d3  路  6Comments

JonesBlunt picture JonesBlunt  路  7Comments

Flone-dnb picture Flone-dnb  路  3Comments

naezith picture naezith  路  10Comments