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();
allocated memory problem
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:
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
.....
wow, im very sorry,
for(int i = 0;i < iBoneCount;i++){
should be
for(int i = 0;i < iKeyFrameCount;i++){
wow, im very sorry,
for(int i = 0;i < iBoneCount;i++){
should be
for(int i = 0;i < iKeyFrameCount;i++){
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++?
You seem to code in C++ but why then are you using old C's calloc and not 'new' from C++?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement