Quoting Henric Andersson ([EMAIL PROTECTED]):
> I've made a program that uses TrueType fonts quite extensively. What I've noticed is
>that the program is leaking memory. ALOT of memory. I traced it to the font loading.
>
> Correct me if I'm wrong, but isn't this how it is supposed to be used:
>
> DFBFontDescription font_dsc;
> IDirectFBFont *font = NULL; // Our font
>
> font_dsc.flags = DFDESC_HEIGHT;
> font_dsc.height = 30;
> DFBCHECK (dfb->CreateFont (dfb, "arial.ttf", &font_dsc, &font));
> DFBCHECK (primary->SetFont (primary, font));
>
> *** do something with the font, ie, draw stuff on screen :) ***
>
> font->Release(font);
>
> If you run this in a loop, the program will eventually fail to load the font, and
>before it does, it will eat alot of memory.
>
> Any comments are welcomed...
I wrote a small test app and it works perfectly.
--
Best regards,
Denis Oliver Kropp
.------------------------------------------.
| DirectFB - Hardware accelerated graphics |
| http://www.directfb.org/ |
"------------------------------------------"
Convergence GmbH
#include <pthread.h>
#include <directfb.h>
#define CHECK(x) \
{ \
DFBResult ret = x; \
\
if (ret) \
DirectFBErrorFatal (#x, ret); \
}
int
main (int argc, char *argv[])
{
int i, n;
DFBResult ret;
IDirectFB *dfb;
IDirectFBSurface *primary;
DFBSurfaceDescription desc;
CHECK( DirectFBInit (&argc, &argv) );
CHECK( DirectFBCreate (&dfb) );
dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN);
desc.flags = DSDESC_CAPS;
desc.caps = DSCAPS_PRIMARY;
CHECK( dfb->CreateSurface (dfb, &desc, &primary) );
primary->Clear (primary, 0, 0, 0, 0);
primary->GetSize (primary, NULL, &n);
n /= 2;
sleep (1);
for (i=4; i < n; i++)
{
DFBFontDescription desc;
IDirectFBFont *font;
desc.flags = DFDESC_HEIGHT;
desc.height = i;
CHECK( dfb->CreateFont (dfb, FONT, &desc, &font) );
CHECK( primary->SetFont (primary, font) );
primary->SetColor (primary, i*256/n, i*256/n, i*256/n, 0xff);
primary->DrawString (primary, "Hello World", -1, 0, i, DSTF_TOPLEFT);
font->Release (font);
}
sleep (2);
primary->Release (primary);
dfb->Release (dfb);
return 0;
}