malloc, free, structs
I have a struct
RECT *Collision;
and I want to have a rect for each of the frames of a sprite, so I do
Collision = calloc(number_of_frames, sizeof(RECT));
but when it comes time to free and I do free(Collision); MSVC throws up an exception and says that theres a problem, I can''t remember what it is exactly off the top of my head, but I''m guessing it was something like MSVC doing ASSERT(Collision->Head) to find out if the members of the struct Collision are pointers, so it can free them, but I don''t want the members of Collision free()''d because they''re just ints, I want Collision itself free()''d.
Am I missing something here?
I''d appreciate any help.
------------
- outRider -
Try using C++ operators, maybe It''ll work better there.
RECT *Collision;
Collision = new RECT[number_of_frames];
...
delete [] Collision;
- Goblineye Entertainment
The road to success is always under construction
RECT *Collision;
Collision = new RECT[number_of_frames];
...
delete [] Collision;
- Goblineye Entertainment
The road to success is always under construction
Goblineye EntertainmentThe road to success is always under construction
Well, I fixed the above by typecasting, since calloc() returns a void*. But now, when I'm free()ing I get the following error from MSVC.
DAMAGE: after normal block (#19) at 0x00990220
Here's basically what I'm doing.
Everything works fine until I get to free()ing.
------------
- outRider -
Edited by - outRider on September 30, 2000 9:34:38 PM
DAMAGE: after normal block (#19) at 0x00990220
Here's basically what I'm doing.
short int *XAxis;short int *YAxis;BYTE *DisplayTime;RECT *Collision;RECT *HitCollision;...XAxis = (short int *)calloc(FrameCount, sizeof(short int));YAxis = (short int *)calloc(FrameCount, sizeof(short int));DisplayTime = (BYTE *)calloc(FrameCount, sizeof(BYTE));Collision = (RECT *)calloc(FrameCount, sizeof(RECT));HitCollision = (RECT *)calloc(FrameCount, sizeof(RECT));//read values for each frame from text file into appropriate varssscanf(TextLine, "x%d, y%d, t%d, rt%d, rl%d, rb%d, rr%d, rt%d, rl%d, rb%d, rr%d", &XAxis<i>, &YAxis[i], &DisplayTime[i], &Collision[i].top, &Collision[i].left, &Collision[i].bottom, &Collision[i].right, &HitCollision[i].top, &HitCollision[i].left, &HitCollision[i].bottom, &HitCollision[i].right);...free(XAxis);free(YAxis);free(DisplayTime);free(Collision);free(HitCollision);
Everything works fine until I get to free()ing.
------------
- outRider -
Edited by - outRider on September 30, 2000 9:34:38 PM
1)Not checking for NULL returned from calloc
2)Where is the 'i' value coming from in the sscanf(...) function
3)Does '...' mean code that shouldn't matter, or code that doesn't touch the calloc'd variables?
[edit]
4)Have you debugged it? Which free gives the assertion, the first one, or the first one on the rects?
Edited by - JonStelly on October 1, 2000 1:17:30 AM
2)Where is the 'i' value coming from in the sscanf(...) function
3)Does '...' mean code that shouldn't matter, or code that doesn't touch the calloc'd variables?
[edit]
4)Have you debugged it? Which free gives the assertion, the first one, or the first one on the rects?
Edited by - JonStelly on October 1, 2000 1:17:30 AM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement