freetype
[Top][All Lists]
Advanced

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

Re: [ft] FT_Load_Glyph returns an error


From: YuGiOhJCJ Mailing-List
Subject: Re: [ft] FT_Load_Glyph returns an error
Date: Sat, 12 Nov 2016 23:30:42 +0100

On Sat, 12 Nov 2016 16:47:42 +0100 (CET)
Werner LEMBERG <address@hidden> wrote:

> 
> > The FreeType error code is "36".  How to know the meaning of this
> > FreeType error code please?
> 
> Value 36 is 0x24.  Looking into file `fterrdef.h' you can find
> 
>   FT_ERRORDEF_( Invalid_Size_Handle,                         0x24,
>                 "invalid size handle" )
> 
> > Here is the new code: [...]
> 
> And indeed, you have forgotten to set a proper size (with
> `FT_Set_Char_Size', for example) before calling `FT_Load_Glyph'.
> 
> 

Thank you, it works now but I have some memory leaks (74 allocs, 68 frees).

Here is the new code:
---
#include <ft2build.h> /* for FT_Init_FreeType */
#include <stdlib.h> /* for exit */
#include FT_FREETYPE_H
int main()
{
        /* https://www.freetype.org/freetype2/docs/tutorial/step1.html */
        FT_Library library;
        FT_Face face;
        FT_UInt glyph_index;
        int error = FT_Init_FreeType(&library);
        if(error != 0)
        {
                fprintf(stderr, "Unable to create a FreeType library object 
(error = \"%d\").\n", error);
                exit(EXIT_FAILURE);
        }
        error = FT_New_Face(library, "Arial.TTF", 0, &face);
        if(error != 0)
        {
                fprintf(stderr, "Unable to create a FreeType face object (error 
= \"%d\").\n", error);
                exit(EXIT_FAILURE);
        }
        error = FT_Set_Char_Size(face, 0, 16*64, 300, 300);
        if(error != 0)
        {
                fprintf(stderr, "Unable to set the character size of a FreeType 
face object (error = \"%d\").\n", error);
                exit(EXIT_FAILURE);
        }
        glyph_index = FT_Get_Char_Index(face, 0x00041);
        error = FT_Load_Glyph(face, glyph_index, 0);
        if(error != 0)
        {
                fprintf(stderr, "Unable to load the glyph image of a FreeType 
face object (error = \"%d\").\n", error);
                exit(EXIT_FAILURE);
        }
        error = FT_Done_Face(face);
        if(error != 0)
        {
                fprintf(stderr, "Unable to destroy a FreeType face object 
(error = \"%d\").\n", error);
                exit(EXIT_FAILURE);
        }
        error = FT_Done_FreeType(library);
        if(error != 0)
        {
                fprintf(stderr, "Unable to destroy a FreeType library object 
(error = \"%d\").\n", error);
                exit(EXIT_FAILURE);
        }
        exit(EXIT_SUCCESS);
}
---

Here are the memory leaks:
---
$ valgrind ./a.out 
==1477== Memcheck, a memory error detector
==1477== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==1477== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==1477== Command: ./a.out
==1477== 
==1477== 
==1477== HEAP SUMMARY:
==1477==     in use at exit: 18,604 bytes in 6 blocks
==1477==   total heap usage: 74 allocs, 68 frees, 53,175 bytes allocated
==1477== 
==1477== LEAK SUMMARY:
==1477==    definitely lost: 0 bytes in 0 blocks
==1477==    indirectly lost: 0 bytes in 0 blocks
==1477==      possibly lost: 0 bytes in 0 blocks
==1477==    still reachable: 18,604 bytes in 6 blocks
==1477==         suppressed: 0 bytes in 0 blocks
==1477== Rerun with --leak-check=full to see details of leaked memory
==1477== 
==1477== For counts of detected and suppressed errors, rerun with: -v
==1477== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
---

Did I forget to free something in my code please?



reply via email to

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