VC++ HELP!!!

Started by
4 comments, last by R67en 20 years, 3 months ago
I get the following error when compiling my app in VC++6: HEAP[WGP11.exe]: Invalid Address specified to RtlValidateHeap( 00360000, 0032F06C ) I had the program working fine, changed a few things, then it began to have this runtime error and would hang. I undid my changes to no avail. Finally, I put some return statements to halt my code at certain points, which pointed me toward the problem. I have found that when I replace a certain variable in a for loop with it''s actual value 5, the program runs, which makes no sense. I then tried a backup version of my program that ran correctly two weeks ago. It no longer runs, which makes me wonder if the problem isnt in VC++ itself. Has anyone else seen this error? Any suggestions? Can anyone explain what this means exactly? I don''t undcerstand how I have much control if any of the heap or how I could be feeding the wrong address( or the right address for that matter). Please help, thanks.
Advertisement
Maybe you are corrupting your memory? If you post some actual code, it''s far easier to offer advice.
Sorry, the code is pretty involved. I was hoping maybe someone would just offer an explaantion for the error and I could plug away at it until I solved the problem. ANyway, Here's some relevant code, I'll try to make sense out of it:


//numEnemyTypes is involved in the error
//this for loop works
for(index=0;index < numEnemyTypes;index++)
{

//build animation for each enemy type
BuildAnimation(&masterImage[index], &masterAnim[index],Fnames [index]);
...
...
}

// the following code fails
//if I replace numEnemyTypes with 5, it runs
//if I replace it with 6 or 7, it runs, masterImage[] has only
//five used members of its 20 capacity
for(index=0;index < numEnemyTypes;index++)
Unload_Bitmap_File(&masterImage[index]);.


//Here is BuildAnimation, although Im pretty sure the problem is not here
//the function takes a Bitmap imaage and loads the data into a structure
//ANIM_OBJ_PTR anim, and initializes the struct's members from a textfile
//I beleive it is working correctly
bool BuildAnimation(BITMAP_FILE_PTR image, ANIM_OBJ_PTR anim, string textFile)
{
fstream file;
file.open(textFile.c_str(),ios::in);

//text file line one
char filename[20];
int sourceImageTotalCells;
int sourceImageCellWidth;
int sourceImageCellHeight;

//text file line two
int pixelWidth;
int pixelHeight;
int attr;//
int systemOrVideoMemory;
//add ability for system

//text file line three
int mode;
int animstate;

//text file line four
int x;
int y;
int radius;


//text file line five
int upBnd;
int rightBnd;
int downBnd;
int leftBnd;

//text file line six
int direction=-2792;


file >>filename>>sourceImageTotalCells>>sourceImageCellWidth>>sourceImageCellHeight;

file >> pixelWidth >> pixelHeight >> attr >> systemOrVideoMemory;
file >> mode >> animstate;
file >> x >> y >> radius;
file >> upBnd >> rightBnd >> downBnd >> leftBnd;
file >> direction;

if(direction==-2792)//test that last member was loaded coorectly from file
return false;
if(!Load_Bitmap_File(image,filename))
Error("Bitmap marioHead Load Error");

for(int iframe=0;iframe {
int tileX=0;
int tileY=0;
tileY=iframe/sourceImageCellWidth;
tileX=iframe%sourceImageCellWidth;
if(!Create_Anim(anim,iframe,pixelWidth,pixelHeight,attr,DDSCAPS_SYSTEMMEMORY))
Error("error creating marioHead sprite");

if(!Load_Anim(anim, iframe, image,tileX,tileY,mode))
Error("error loading marioHead sprite");


}
anim->state=animstate;
anim->x=x;
anim->y=y;
anim->radius=radius;
anim->bounds[UP]=upBnd;
anim->bounds[RIGHT]=rightBnd;
anim->bounds[DOWN]=downBnd;
anim->bounds[LEFT]=leftBnd;
anim->direction=direction;
//should read in a separate number beisdes totalcells for frames used
anim->framesUsed=sourceImageTotalCells;

Unload_Bitmap_File(image);
file.close();
return true;
}


//here is Unload_Bitmap_File, which is where the error is somehow
//centered around
int Unload_Bitmap_File(BITMAP_FILE_PTR bitmap)
{
// this function releases all memory associated with "bitmap"
if (bitmap->buffer)
{
// release memory
free(bitmap->buffer);

// reset pointer
bitmap->buffer = NULL;

} // end if

// return success
return(1);

} // end Unload_Bitmap_File


thanks for the help; I hope you can make some sense of my code- this is a pretty central part of my game that's hard to guide someone through.





[edited by - R67en on January 5, 2004 11:46:45 PM]

[edited by - R67en on January 5, 2004 11:47:19 PM]


[edited by - R67en on January 5, 2004 11:48:46 PM]


[edited by - R67en on January 5, 2004 11:49:13 PM]

IMHO it sound like you are freeing something that is not allocated. or you changed a memory location before you allocate it. thats why the heap is complaining.
check your code for any used pointers before allocating memory to it.
you could check at which value of numEnemyTypes did the error
you could check your file pointer bitmap before the function or after it.


This topic is closed to new replies.

Advertisement