1
General / 2.4.1 Memory leak with sf::Text?
« on: January 19, 2017, 06:04:11 am »
Hello, just recently I've noticed an odd memory leak with sf::Text in one of my project. That being because of how I'm on [Windows 7 with Visual Studio 2015 Community and thus using the CRT library to detect memory leaks.
Anyways, I've been able to recreate the memory leak report by using the member function setOutlineThickness on a text object and then proceeding to draw that object to a window. When I don't give the text an outline thickness I get no leak report. Also, If I specify the outline thickness and don't draw I don't get the report. More so, the type of font the text is using doesn't matter, I get the same results.
I've also commented parts of my code to give insight and also to show the lines that are suspected to be causing this leak. Can anyone else see if I'm doing something wrong or is possibly able to replicate this?
Thank you for your time and help.
Anyways, I've been able to recreate the memory leak report by using the member function setOutlineThickness on a text object and then proceeding to draw that object to a window. When I don't give the text an outline thickness I get no leak report. Also, If I specify the outline thickness and don't draw I don't get the report. More so, the type of font the text is using doesn't matter, I get the same results.
I've also commented parts of my code to give insight and also to show the lines that are suspected to be causing this leak. Can anyone else see if I'm doing something wrong or is possibly able to replicate this?
#define _CRTDBG_MAP_ALLOC
#include <SFML\Graphics.hpp>
#include <iostream>
#include <stdlib.h>
#include <crtdbg.h>
void test() {
sf::RenderWindow window(sf::VideoMode(720, 360), "TESTING");
sf::Font font;
font.loadFromFile("media/fonts/default/arial.ttf"); //font has no effect, same results.
sf::Text text("This is a pretty freaking cool font.", font, 24U);
text.setOutlineColor(sf::Color::White);
text.setOutlineThickness(1.75f); //enabling this results in a memory leak only if the resulting text is drawn, otherwise no leak.
text.setFillColor(sf::Color::Green);
while (window.isOpen()) {
sf::Event ev;
while (window.pollEvent(ev)) {
if (ev.type == sf::Event::Closed) {
window.close();
}
}
text.setPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition(window)));
window.draw(text); // if the text has a value for outlineThickness there is a memory leak when it's drawn, otherwise there is no leak.
window.display();
window.clear(sf::Color::Black);
}
}
void textTest() {
sf::Font font;
font.loadFromFile("media/fonts/default/arial.ttf");
sf::Text txt("Test", font, 24U);
txt.setOutlineColor(sf::Color::Black);
txt.setOutlineThickness(1.5f);
txt.setFillColor(sf::Color::White);
txt.setPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition()));
}
int main() {
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); //automatically dump a report on exit
test();
//textTest(); //No memory leak when it is constructed even when you specify outlineThickness.
return EXIT_SUCCESS;
}
#include <SFML\Graphics.hpp>
#include <iostream>
#include <stdlib.h>
#include <crtdbg.h>
void test() {
sf::RenderWindow window(sf::VideoMode(720, 360), "TESTING");
sf::Font font;
font.loadFromFile("media/fonts/default/arial.ttf"); //font has no effect, same results.
sf::Text text("This is a pretty freaking cool font.", font, 24U);
text.setOutlineColor(sf::Color::White);
text.setOutlineThickness(1.75f); //enabling this results in a memory leak only if the resulting text is drawn, otherwise no leak.
text.setFillColor(sf::Color::Green);
while (window.isOpen()) {
sf::Event ev;
while (window.pollEvent(ev)) {
if (ev.type == sf::Event::Closed) {
window.close();
}
}
text.setPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition(window)));
window.draw(text); // if the text has a value for outlineThickness there is a memory leak when it's drawn, otherwise there is no leak.
window.display();
window.clear(sf::Color::Black);
}
}
void textTest() {
sf::Font font;
font.loadFromFile("media/fonts/default/arial.ttf");
sf::Text txt("Test", font, 24U);
txt.setOutlineColor(sf::Color::Black);
txt.setOutlineThickness(1.5f);
txt.setFillColor(sf::Color::White);
txt.setPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition()));
}
int main() {
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); //automatically dump a report on exit
test();
//textTest(); //No memory leak when it is constructed even when you specify outlineThickness.
return EXIT_SUCCESS;
}
Thank you for your time and help.