[BUG] Corrected some bugs introduced in r383

[BUG] GRRLIB_FreeBMF was not freeing the memory completely
This commit is contained in:
Crayon2000 2010-07-09 06:07:56 +00:00
parent 09c55dd214
commit 1561726543
3 changed files with 11 additions and 5 deletions

View file

@ -59,6 +59,7 @@ GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) {
memcpy(fontArray->name, &my_bmf[18 + numcolpal], j); memcpy(fontArray->name, &my_bmf[18 + numcolpal], j);
j = 18 + numcolpal + j; j = 18 + numcolpal + j;
fontArray->nbChar = (my_bmf[j] | my_bmf[j+1]<<8); fontArray->nbChar = (my_bmf[j] | my_bmf[j+1]<<8);
memset(fontArray->charDef, 0, 256 * sizeof(GRRLIB_bytemapChar));
j++; j++;
for (i=0; i < fontArray->nbChar; i++) { for (i=0; i < fontArray->nbChar; i++) {
c = my_bmf[++j]; c = my_bmf[++j];
@ -82,14 +83,18 @@ GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) {
* Free memory allocated by ByteMap fonts. * Free memory allocated by ByteMap fonts.
* @param bmf A GRRLIB_bytemapFont structure. * @param bmf A GRRLIB_bytemapFont structure.
*/ */
void GRRLIB_FreeBMF (const GRRLIB_bytemapFont *bmf) { void GRRLIB_FreeBMF (GRRLIB_bytemapFont *bmf) {
u16 i; u16 i;
for (i=0; i<bmf->nbChar; i++) { for (i=0; i<256; i++) {
if(bmf->charDef[i].data) {
free(bmf->charDef[i].data); free(bmf->charDef[i].data);
} }
}
free(bmf->palette); free(bmf->palette);
free(bmf->name); free(bmf->name);
free(bmf);
bmf = NULL;
} }
/** /**

View file

@ -86,11 +86,12 @@ void GRRLIB_PrintBMF (const f32 xpos, const f32 ypos,
pdata = pchar->data; pdata = pchar->data;
for (y=0; y<pchar->height; y++) { for (y=0; y<pchar->height; y++) {
for (x=0; x<pchar->width; x++) { for (x=0; x<pchar->width; x++) {
if (*pdata++) { if (*pdata) {
GRRLIB_Plot(xoff + x + pchar->relx, GRRLIB_Plot(xoff + x + pchar->relx,
ypos + y + pchar->rely, ypos + y + pchar->rely,
bmf->palette[*pdata]); bmf->palette[*pdata]);
} }
pdata++;
} }
} }
xoff += pchar->kerning + bmf->tracking; xoff += pchar->kerning + bmf->tracking;

View file

@ -44,7 +44,7 @@ THE SOFTWARE.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// GRRLIB_bmf.c - BitMapFont functions // GRRLIB_bmf.c - BitMapFont functions
GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ); GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] );
void GRRLIB_FreeBMF (const GRRLIB_bytemapFont *bmf); void GRRLIB_FreeBMF (GRRLIB_bytemapFont *bmf);
void GRRLIB_InitTileSet (GRRLIB_texImg *tex, void GRRLIB_InitTileSet (GRRLIB_texImg *tex,
const uint tilew, const uint tileh, const uint tilew, const uint tileh,