Jump to content
  • Advertisement
Sign in to follow this  
Nazdreg

allocated memory problem

This topic is 3030 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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:
struct MATRIXATTRIB
{
	float data[10];
};
 
int iBoneCount;
int iKeyFrameCount;
MATRIXATTRIB** BoneData;
//BoneData[keyframe][bone][data element]
 
ifstream file(filename, ios::in);
if(!file){
	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 = (MATRIXATTRIB*) calloc(iBoneCount, sizeof(MATRIXATTRIB));
	if(!BoneData)assert(!"MeshAnim::Load() | BoneData 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[j].data[k] = 1.0f;
			else
				file >> BoneData[j].data[k];
			if(i == 48 && j == 0)assert(!"after reading");
		}
	}
}
//finished reading file
file.close();


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
Advertisement
.....
wow, im very sorry,
for(int i = 0;i < iBoneCount;i++){
should be
for(int i = 0;i < iKeyFrameCount;i++){

Share this post


Link to post
Share on other sites
Just some other thin:
You seem to code in C++ but why then are you using old C's calloc and not 'new' from C++?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!