mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-02 20:43:35 +00:00
Fix undefined behavior with custom fonts;
This commit is contained in:
parent
e474bb61d1
commit
05dd988cb8
|
@ -16,6 +16,7 @@ FontData* lovrFontDataCreate(Blob* blob, int size) {
|
||||||
FT_Error err = FT_Err_Ok;
|
FT_Error err = FT_Err_Ok;
|
||||||
if (blob) {
|
if (blob) {
|
||||||
err = err || FT_New_Memory_Face(ft, blob->data, blob->size, 0, &face);
|
err = err || FT_New_Memory_Face(ft, blob->data, blob->size, 0, &face);
|
||||||
|
lovrRetain(&blob->ref);
|
||||||
} else {
|
} else {
|
||||||
err = err || FT_New_Memory_Face(ft, Cabin_ttf, Cabin_ttf_len, 0, &face);
|
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* fontData = malloc(sizeof(FontData));
|
||||||
fontData->rasterizer = face;
|
fontData->rasterizer = face;
|
||||||
|
fontData->blob = blob;
|
||||||
fontData->size = size;
|
fontData->size = size;
|
||||||
|
|
||||||
FT_Size_Metrics metrics = face->size->metrics;
|
FT_Size_Metrics metrics = face->size->metrics;
|
||||||
|
@ -39,6 +41,9 @@ FontData* lovrFontDataCreate(Blob* blob, int size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void lovrFontDataDestroy(FontData* fontData) {
|
void lovrFontDataDestroy(FontData* fontData) {
|
||||||
|
if (fontData->blob) {
|
||||||
|
lovrRelease(&fontData->blob->ref);
|
||||||
|
}
|
||||||
FT_Done_Face(fontData->rasterizer);
|
FT_Done_Face(fontData->rasterizer);
|
||||||
free(fontData);
|
free(fontData);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void* rasterizer;
|
void* rasterizer;
|
||||||
|
Blob* blob;
|
||||||
int size;
|
int size;
|
||||||
int height;
|
int height;
|
||||||
int ascent;
|
int ascent;
|
||||||
|
|
Loading…
Reference in a new issue