Realloc problems with sturcture array inside structure
I have searched the forum and cant find the answer so i thought that i would ask.
I am using C and have the following two structures:
typedef struct{
int origX, origY, origZ, maxLengthBool;
float currentLength[3];
float dirX, dirY, dirZ;
double maxLength;
}BRANCH;
typedef struct{
int branchCount;
BRANCH *branches;
COLOUR treeColour;
int dirBias;
}TREE;
You should be able to see that there is a pointer for branch in the tree sturucture.
I can assign memeory using calloc for the BRANCH pojnter/array
mainTree->branches = calloc(0,sizeof(BRANCH));
This works and creates an array of branches. But i jave a problem when i try and realloc the memory and increase the size of the array i use this code, which is part of a method/function:
tree->branches = realloc(tree->branches, brSize*sizeof(BRANCH));
Where brSize is the new size that i would like.
In windows using VC++ and openGL it causes a fatal error. I know it is this section, the realloc as the program doesnt get furthur than this point.
Can anyone suggest a solution as i am lost and dont understand the problem.