Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak with freetype fonts [fix] #657

Open
Youlean opened this issue Apr 19, 2023 · 4 comments
Open

Memory leak with freetype fonts [fix] #657

Youlean opened this issue Apr 19, 2023 · 4 comments

Comments

@Youlean
Copy link

Youlean commented Apr 19, 2023

I have noticed that the freetype fonts don't release their memory correctly.

The fix would be:

void fonsDeleteInternal(FONScontext* stash)
{
	int i;
	if (stash == NULL) return;

	if (stash->params.renderDelete)
		stash->params.renderDelete(stash->params.userPtr);

	for (i = 0; i < stash->nfonts; ++i)
		fons__tt_done_face(&stash->fonts[i]->font);
	
	for (i = 0; i < stash->nfonts; ++i)
		fons__freeFont(stash->fonts[i]);

	if (stash->atlas) fons__deleteAtlas(stash->atlas);
	if (stash->fonts) free(stash->fonts);
	if (stash->texData) free(stash->texData);
	if (stash->scratch) free(stash->scratch);
	fons__tt_done(stash);
	free(stash);
}
int fons__tt_done_face(FONSttFontImpl* font)
{
	FT_Error ftError;
	ftError = FT_Done_Face(font->font);
	return ftError == 0;
}
@tazok81
Copy link

tazok81 commented Feb 1, 2024

Hi, I tried add this to my project, but FT_Done_Face is not implemented. What it does?

@mulle-nat
Copy link
Contributor

There are two font libraries used by nanovg, if you use STB (the default) you don't need it.

@tazok81
Copy link

tazok81 commented Feb 1, 2024

thank you

@Youlean
Copy link
Author

Youlean commented Feb 1, 2024

Indeed. If you use STB, you might want to increase font scale so that you can get better font rendering on low DPI screens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants