当使用sf :: Text :: setOutlineThickness时,crtdbg转储内存泄漏

时间:2017-05-16 15:15:21

标签: c++ memory-leaks sfml

在Windows 7 64位版本上使用SFML 2.4.2时,我注意到sf::Text::setOutlineThickness(float)存在问题。一旦在程序中使用它,除了默认值0之外,crtdbg会转储各种大小字节的内存泄漏,但总量相同。我相信这与字符串的大小有关,如果文本被绘制,并且if the parameter of setOutlineThickness is accepted在此处演示:

/// 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);
}

这会产生泄漏:

{8601} normal block at 0x0000000005CA5C90, 60 bytes long.
 Data: <                > 03 00 07 00 0B 00 0F 00 13 00 17 00 1B 00 1F 00
{8600} normal block at 0x0000000005E03A20, 120 bytes long.
 Data: <                > 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
{8599} normal block at 0x0000000005E2A680, 960 bytes long.
 Data: <                > 00 00 00 00 80 07 00 00 0D 01 00 00 80 07 00 00
{8598} normal block at 0x0000000005CA36B0, 72 bytes long.
 Data: <        h       > F0 1A 9D 05 00 00 00 00 68 AE 83 DB FE 07 00 00

如果test.setString("B");,仍有四个块,但字节大小不同,因为字符串使用另一个字符:
68字节,136字节,1088字节,72字节 最后,如果test.setString("AB");,则有8个具有预期大小的块:

{8667} normal block at 0x0000000005C35D10, 68 bytes long.
 Data: <                > 03 00 07 00 0B 00 0F 00 13 00 17 00 1B 00 1F 00
{8666} normal block at 0x0000000005C61310, 136 bytes long.
 Data: <                > 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
{8665} normal block at 0x000000000325CDE0, 1088 bytes long.
 Data: <                > 00 00 00 00 80 07 00 00 0D 01 00 00 80 07 00 00
{8664} normal block at 0x0000000005C340D0, 72 bytes long.
 Data: <        h       > F0 1A 96 05 00 00 00 00 68 AE B5 DB FE 07 00 00
{8601} normal block at 0x0000000005C35C90, 60 bytes long.
 Data: <                > 03 00 07 00 0B 00 0F 00 13 00 17 00 1B 00 1F 00
{8600} normal block at 0x0000000005D93A20, 120 bytes long.
 Data: <                > 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
{8599} normal block at 0x0000000005DBA680, 960 bytes long.
 Data: <                > 00 00 00 00 80 07 00 00 0D 01 00 00 80 07 00 00
{8598} normal block at 0x0000000005C336B0, 72 bytes long.
 Data: <        h       > F0 1A 96 05 00 00 00 00 68 AE B5 DB FE 07 00 00
  • 我使用sf :: Text作为类的私有成员,该类应该与类一起销毁,但似乎并非如此。我错过了什么?
  • 我使用_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);,这是误报吗?
  • 看一下这个函数sf::Text::setOutlineThickness,我在这里看不到问题。 A brief documentation
  • 根据字符串大小的不同泄漏更多的是一种症状,它是轮廓厚度的drawcall和非默认值,我无能为力。

1 个答案:

答案 0 :(得分:1)

Font.cpp#L561

看起来SFML中存在真正的泄漏

看起来像这样:

FT_Glyph_Stroke(&glyphDesc, stroker, false);

但是根据FT_Glyph_Stroke的文档,实际应该是这样,所以源字形被破坏了:

FT_Glyph_Stroke(&glyphDesc, stroker, true);