Im having a little problem with dynamic arrays..
I have a struct:
Code:
typedef struct _SFont
{
ID3DXFont *fontobj;
LOGFONT fontparams;
char *name;
}SFont;
i declare a pointer to that struct:
My class constructor:
Code:
ObjectBuilder::ObjectBuilder()
{
rFont = (SFont*)malloc(sizeof *rFont);
fontnum = 0; //fontnum is a counter
}
I have a function that increases the fontnum and must resize the array:
Code:
void ObjectBuilder::CreateFont(char *Name, int size)
{
fontnum += 1;
//allocate more space
rFont = (SFont*)realloc(rFont, fontnum * sizeof *rFont);
//So, now the array should have fontnum-1 slots, right?
rFont[fontnum].Name = Name;
There is some code to create a font, but thats all we need. The problem is that I can only call 1 time this function, meaning that I can only add 1 more font. If i call it again, it crashes! I free the array using:
Code:
free (rFont);
rFont=NULL;
But when I exit the program, having created 1 font, it crashes for once more in the debug and shows me some asm code. Thank you very much!