Im having a little problem with dynamic arrays..
I have a struct:
i declare a pointer to that struct:Code:typedef struct _SFont { ID3DXFont *fontobj; LOGFONT fontparams; char *name; }SFont;
My class constructor:Code:SFont *rFont;
I have a function that increases the fontnum and must resize the array:Code:ObjectBuilder::ObjectBuilder() { rFont = (SFont*)malloc(sizeof *rFont); fontnum = 0; //fontnum is a counter }
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: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;
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!Code:free (rFont); rFont=NULL;



LinkBack URL
About LinkBacks


