Fix undefined behavior with custom fonts;

This commit is contained in:
bjorn 2017-07-14 23:57:45 +09:00
parent e474bb61d1
commit 05dd988cb8
2 changed files with 6 additions and 0 deletions

View File

@ -16,6 +16,7 @@ FontData* lovrFontDataCreate(Blob* blob, int size) {
FT_Error err = FT_Err_Ok;
if (blob) {
err = err || FT_New_Memory_Face(ft, blob->data, blob->size, 0, &face);
lovrRetain(&blob->ref);
} else {
err = err || FT_New_Memory_Face(ft, Cabin_ttf, Cabin_ttf_len, 0, &face);
}
@ -28,6 +29,7 @@ FontData* lovrFontDataCreate(Blob* blob, int size) {
FontData* fontData = malloc(sizeof(FontData));
fontData->rasterizer = face;
fontData->blob = blob;
fontData->size = size;
FT_Size_Metrics metrics = face->size->metrics;
@ -39,6 +41,9 @@ FontData* lovrFontDataCreate(Blob* blob, int size) {
}
void lovrFontDataDestroy(FontData* fontData) {
if (fontData->blob) {
lovrRelease(&fontData->blob->ref);
}
FT_Done_Face(fontData->rasterizer);
free(fontData);
}

View File

@ -6,6 +6,7 @@
typedef struct {
void* rasterizer;
Blob* blob;
int size;
int height;
int ascent;