[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Resource leak?
From: |
David Turner |
Subject: |
Re: Resource leak? |
Date: |
Wed, 11 Oct 2000 17:41:58 +0200 |
Hello Niels,
> Hi!
>
> I think I discovered a resource leak when using .FNT/.FON windows files.
> When the current face
> is a .TTF the following (see code) works fine. But when I use a .FNT/.FON
> file, there seems to be no deallocation
> of a bitmap structure somewhere (FT_Glyph_Copy??). I must admit I don't
> fully understand what is
> going on.. Excuse my ignorance! ;-)
>
> I use a recent CVS snapshot, last update was a little more than a week ago.
>
> Cheers, Niels.
>
FT_Glyph_Transform should only be called with scalable formats and
returns an FT_Err_Invalid_Glyph_Format error..
as your code does a simple "continue" and doesn't free the copy,
it leaks memory..
an alternative way to do what you need, without copying glyphs is:
for(int i=0; i<num_glyphs; i++, glyph++)
{
FT_BBox bbox;
if (glyph->image==NULL) continue;
FT_Glyph_Get_CBox( glyph->image, ft_glyph_bbox_pixels, &bbox);
vec = glyph->pos;
bbox.yMin += glyph->pos.y;
bbox.yMax += glyph->pos.y;
if (ymin>bbox.yMin) ymin = bbox.yMin;
if (ymax<bbox.yMax) ymax = bbox.yMax;
}
assuming that glyph.pos.y is an integer pixel positions (not 26.6)
Cheers,
- David
> ----------------------------------------------------------------------------
> ------------
>
> // CODE START HERE..
>
> S32 TextRenderer::GetTextHeight(S32 num_glyphs)
> {
> S32 ymin, ymax;
> PGlyph glyph = glyphs;
> FT_Error error;
>
> ymin = 0x7FFFFFFFl;
> ymax = 0x80000000l;
> for(int i=0; i<num_glyphs; i++, glyph++)
> {
> FT_Glyph image;
> FT_Vector vec;
> FT_BBox bbox;
>
> if (glyph->image==NULL) continue;
> error = FT_Glyph_Copy(glyph->image, &image);
> if (error) continue;
> vec = glyph->pos;
> error = FT_Glyph_Transform(image, NULL, &vec);
> if (error) continue;
> FT_Glyph_Get_CBox(image, ft_glyph_bbox_pixels, &bbox);
> if (ymin>bbox.yMin) ymin = bbox.yMin;
> if (ymax<bbox.yMax) ymax = bbox.yMax;
> FT_Done_Glyph(image);
> }
> return ymax;
> }
>
> // CODE ENDS
- Resource leak?, Niels A. Moseley, 2000/10/10
- Re: Resource leak?,
David Turner <=