freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Devel] Leaking FT_Glyph_To_Bitmap


From: Karl Schultz
Subject: RE: [Devel] Leaking FT_Glyph_To_Bitmap
Date: Mon, 20 Jan 2003 09:06:46 -0700

I was initially confused by this function too.  Here is some of my code that
uses the function and how I'm handling the glyph pointer.  Earlier revisions
of the code, based on some misconceptions of mine, would cause leaks or try
to free memory incorrectly.  

I think what I was doing was keeping a copy of the glyph pointer before
calling FT_Glyph_To_Bitmap,
freeing the modified glyph pointer if the call was successful, and then
freeing the saved glyph pointer in the case of either success or failure.

But happily, this end result works, is simpler, and seems to mirror the
examples in the documentation.  Setting the last parm to 1 is important to
note as well.  Your code example at the very bottom sets the last parm to 0.


    for (info = glyphInfo, i=0; i<numGlyphs; i++) {
        
        /* This function makes FreeType render the bitmap.
         *
         * If there is no error, the function overwrites the
         * first argument pointer with a pointer to the
         * "BitmapGlyph", freeing the original "Glyph" data.
         * The pointer must then be cast into the appropriate
         * pointer type to access the BitmapGlyph data.
         *
         * If there is an error, the argument is unchanged.
         *
         * In either case, the glyph (bitmap or not) is freed
         * when we are done with the glyph.
         */
        
        error = FT_Glyph_To_Bitmap(&info->glyph,
                                   ft_render_mode_normal,
                                   NULL, 1);

        if (!error) {
            /* Cast to access bitmap content */
            ftBitmap = (FT_BitmapGlyph)info->glyph;
        
        /* DO WORK */

        } /* if no error */
        
        FT_Done_Glyph(info->glyph);
        info++;                         /* next glyph */
    } /* for each glyph */

> -----Original Message-----
> From: Patrick Hoffmann [mailto:address@hidden
> Sent: Saturday, January 18, 2003 3:03 AM
> To: address@hidden
> Subject: AW: [Devel] Leaking FT_Glyph_To_Bitmap
> 
> 
> I do call FT_Done_Glyph() (later in my code) and it works mostly fine.
> Except the struct created by FT_Glyph_To_Bitmap! I have to delete it
> manually before calling FT_Done_Glyph().
> 
> -----Ursprüngliche Nachricht-----
> Von: address@hidden [mailto:address@hidden Im
> Auftrag von David Turner
> Gesendet: Freitag, 17. Januar 2003 16:32
> An: address@hidden
> Betreff: Re: [Devel] Leaking FT_Glyph_To_Bitmap
> 
> 
> Hello Patrick,
> 
> Patrick Hoffmann wrote:
> > Hi freetype folx...
> > 
> > I found a leak (or a misktake of myself ;) in FreeType 2.
> > 
> > When I user FT_Glyph_To_Bitmap() I need to delete the bitmap buffer 
> > and the bitmap it self by my own. I didn't found any hint 
> about that 
> > in the documentation, so I think this might be a memory leak bug.
> > 
> > Any ideas?
> >
> FT_Glyph objects are not monitored by the library, you need to destroy
> them yourself (unlike FT_Size/FT_GlyphSlot/FT_CharMap objects 
> which are
> automatically destroyed when FT_Done_Face or FT_Done_FreeType are
> called)
> 
> When FT_Glyph_To_Bitmap is called, it really creates a new FT_Glyph
> object and changes your "image" handle to point to it. you should call
> FT_Done_Glyph to destroy it when you don't need it anymore..
> 
> I don't think this is a memory leak, just normal behaviour for the
> library...
> 
> Hope this helps,
> 
> - David Turner
> - The FreeType Project  (www.freetype.org)
> 
> 
> > Here is the code...
> > 
> >     FT_Glyph        image = it->m_ftglyph;
> > 
> >     e = FT_Glyph_To_Bitmap( &image, ft_render_mode_normal, &pen, 0
> > );
> >     if( !e )
> >     {
> >             FT_BitmapGlyph  bit = (FT_BitmapGlyph)image;
> > 
> >             Driver_Display_Bitmap( ... );
> > 
> >             // Undocumented: must delete these both...
> >             delete [] bit->bitmap.buffer;
> >             delete bit;
> >     }
> > 
> > 
> > _______________________________________________
> > Devel mailing list
> > address@hidden http://www.freetype.org/mailman/listinfo/devel
> > 
> 
> 
> 
> _______________________________________________
> Devel mailing list
> address@hidden http://www.freetype.org/mailman/listinfo/devel
> 
> 
> _______________________________________________
> Devel mailing list
> address@hidden
> http://www.freetype.org/mailman/listinfo/devel
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]