diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/text.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/ui/text.c b/src/ui/text.c index 2b3e187d..cf974366 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -450,15 +450,10 @@ iLocalDef iFont *font_Text_(enum iFontId id) { | |||
450 | return &text_.fonts[id & mask_FontId]; | 450 | return &text_.fonts[id & mask_FontId]; |
451 | } | 451 | } |
452 | 452 | ||
453 | static void freeBmp_(void *ptr) { | ||
454 | stbtt_FreeBitmap(ptr, NULL); | ||
455 | } | ||
456 | |||
457 | static SDL_Surface *rasterizeGlyph_Font_(const iFont *d, uint32_t glyphIndex, float xShift) { | 453 | static SDL_Surface *rasterizeGlyph_Font_(const iFont *d, uint32_t glyphIndex, float xShift) { |
458 | int w, h; | 454 | int w, h; |
459 | uint8_t *bmp = stbtt_GetGlyphBitmapSubpixel( | 455 | uint8_t *bmp = stbtt_GetGlyphBitmapSubpixel( |
460 | &d->font, d->xScale, d->yScale, xShift, 0.0f, glyphIndex, &w, &h, 0, 0); | 456 | &d->font, d->xScale, d->yScale, xShift, 0.0f, glyphIndex, &w, &h, 0, 0); |
461 | collect_Garbage(bmp, freeBmp_); /* `bmp` must be freed afterwards. */ | ||
462 | SDL_Surface *surface8 = | 457 | SDL_Surface *surface8 = |
463 | SDL_CreateRGBSurfaceWithFormatFrom(bmp, w, h, 8, w, SDL_PIXELFORMAT_INDEX8); | 458 | SDL_CreateRGBSurfaceWithFormatFrom(bmp, w, h, 8, w, SDL_PIXELFORMAT_INDEX8); |
464 | SDL_SetSurfacePalette(surface8, text_.grayscale); | 459 | SDL_SetSurfacePalette(surface8, text_.grayscale); |
@@ -466,6 +461,7 @@ static SDL_Surface *rasterizeGlyph_Font_(const iFont *d, uint32_t glyphIndex, fl | |||
466 | SDL_Surface *surface = SDL_ConvertSurface(surface8, fmt, 0); | 461 | SDL_Surface *surface = SDL_ConvertSurface(surface8, fmt, 0); |
467 | SDL_FreeFormat(fmt); | 462 | SDL_FreeFormat(fmt); |
468 | SDL_FreeSurface(surface8); | 463 | SDL_FreeSurface(surface8); |
464 | stbtt_FreeBitmap(bmp, NULL); | ||
469 | return surface; | 465 | return surface; |
470 | } | 466 | } |
471 | 467 | ||
@@ -535,7 +531,8 @@ static void cache_Font_(iFont *d, iGlyph *glyph, int hoff) { | |||
535 | const SDL_Rect dstRect = sdlRect_(*glRect); | 531 | const SDL_Rect dstRect = sdlRect_(*glRect); |
536 | SDL_RenderCopy(render, tex, &(SDL_Rect){ 0, 0, dstRect.w, dstRect.h }, &dstRect); | 532 | SDL_RenderCopy(render, tex, &(SDL_Rect){ 0, 0, dstRect.w, dstRect.h }, &dstRect); |
537 | SDL_DestroyTexture(tex); | 533 | SDL_DestroyTexture(tex); |
538 | iAssert(surface); | 534 | } |
535 | if (surface) { | ||
539 | SDL_FreeSurface(surface); | 536 | SDL_FreeSurface(surface); |
540 | } | 537 | } |
541 | } | 538 | } |