Sign in to follow this  

allocated memory problem

Recommended Posts

Hi, I am making a program that reads a file containing animation data for a mesh, and it works fine for 48 keyframes, but when i add one more keyframe and try to load the animation, the program just closes at the point where i load the data from the file. Each keyframe consists of 480 floats. Here is my code for loading and reading the file:
	float data[10];
int iBoneCount;
int iKeyFrameCount;
//BoneData[keyframe][bone][data element]
ifstream file(filename, ios::in);
	assert(!"MeshAnim::Load() | error loading file");
file >> iBoneCount;	//is 48 in test animation
file >> iKeyFrameCount;	//problem occurs when 49 or above
BoneData = (MATRIXATTRIB**) calloc(iKeyFrameCount, sizeof(MATRIXATTRIB*));
if(!BoneData)assert(!"MeshAnim::Load() | BoneData allocation failed");
for(int i = 0;i < iBoneCount;i++){
	BoneData[i] = (MATRIXATTRIB*) calloc(iBoneCount, sizeof(MATRIXATTRIB));
	if(!BoneData[i])assert(!"MeshAnim::Load() | BoneData[i] allocation failed");
for(int i = 0;i < iKeyFrameCount;i++){
	for(int j = 0;j < iBoneCount;j++){
		for(int k = 0;k < 10;k++){
			if(i == 48 && j == 0)assert(!"before reading");
			if(i == 48 && j == 0)
				BoneData[i][j].data[k] = 1.0f;
				file >> BoneData[i][j].data[k];
			if(i == 48 && j == 0)assert(!"after reading");
//finished reading file

when i run this, the first assert "before reading" is displayed, but when i click ignore, the second assert does not appear, and my program just quits, without saying anything. So i can see that the program is failing when i try to assign a variable to BoneDate[48][0][0], which is very odd, as i have checked, and iKeyFrameCount is definately 49, before and after allocating memory for BoneData, and also the allocation for BoneData is succesfull Could anyone please enlighten me to why this is happening? Thanks in advance, Nazdreg

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this