SDL and TTF freeing problems?

Hello, I seem to have problems with SDL_FreeSurface and TTF_CloseFont, when I
pre-open a font and then pass it to several of my classes ( I’m passing the
same font ), they work fine and it greatly speeds up the blitting and loading
for my program, but when I close them it crashes, that’s probably because the
first object closes the font and the second wants to do the same, but can’t,
since the data is already invalidated.

With SDL_FreeSurface I can make a copy of the pre-loaded surface and then pass
it to the different objects using SDL_DisplayFormat or SDL_DisplayFormatAlpha,
but with TTF I have no idea how to do such a thing, is there any way to prevent
different objects from trying to delete the same font data or to copy a
TTF_Font?

Thanks,
Creature

SDL_Surface has a Refcount member for problems like this. Just make sure you increment it every time each new object gets ahold of it. Then they can call SDL_FreeSurface all they want, and it won’t get freed until every reference has checked in first.>----- Original Message ----

From: Creature
Subject: [SDL] SDL and TTF freeing problems?

Hello, I seem to have problems with SDL_FreeSurface and TTF_CloseFont, when I
pre-open a font and then pass it to several of my classes ( I’m passing the
same font ), they work fine and it greatly speeds up the blitting and loading
for my program, but when I close them it crashes, that’s probably because the
first object closes the font and the second wants to do the same, but can’t,
since the data is already invalidated.

With SDL_FreeSurface I can make a copy of the pre-loaded surface and then pass
it to the different objects using SDL_DisplayFormat or SDL_DisplayFormatAlpha,
but with TTF I have no idea how to do such a thing, is there any way to prevent
different objects from trying to delete the same font data or to copy a
TTF_Font?

Thanks,
Creature

Mason Wheeler <masonwheeler yahoo.com> writes:

SDL_Surface has a Refcount member for problems like this. Just make sure you
increment it every time each
new object gets ahold of it. Then they can call SDL_FreeSurface all they
want, and it won’t get freed until
every reference has checked in first.

Hello, I seem to have problems with SDL_FreeSurface and TTF_CloseFont, when
I

pre-open a font and then pass it to several of my classes ( I’m passing the
same font ), they work fine and it greatly speeds up the blitting and
loading

for my program, but when I close them it crashes, that’s probably because
the

first object closes the font and the second wants to do the same, but can’t,
since the data is already invalidated.

With SDL_FreeSurface I can make a copy of the pre-loaded surface and then
pass

it to the different objects using SDL_DisplayFormat or
SDL_DisplayFormatAlpha,

but with TTF I have no idea how to do such a thing, is there any way to
prevent

different objects from trying to delete the same font data or to copy a
TTF_Font?

Thanks,
Creature

Yes, that seems to work, thanks.

Anyone have any idea’s on the TTF_Font * problem though? Unlike SDL_Surfaces,
TTF_Font doesn’t have a refcount, but the surfaces generated by the font do
though…> >----- Original Message ----

From: Creature <modjusticar hotmail.com>
Subject: [SDL] SDL and TTF freeing problems?

If the problem’s with the font structs themselves, then the solution is simple. Just don’t have the object take ownership of them. Don’t free them in the objects’ destructor; keep track of them separately and free them when whatever routine originally allocated them terminates.>----- Original Message ----

From: Creature
Subject: Re: [SDL] SDL and TTF freeing problems?

Yes, that seems to work, thanks.

Anyone have any idea’s on the TTF_Font * problem though? Unlike SDL_Surfaces,
TTF_Font doesn’t have a refcount, but the surfaces generated by the font do
though…