Advertisement

Odd C++ Error

Started by February 09, 2001 03:37 AM
3 comments, last by Galileo430 23 years, 11 months ago
Ok for some reason my console application errors AFTER the end of the program. my main() returns 0. Then I get a 0xC00005 access error along with a prompt. "DEBUG ERROR:" "DAMAGE: after Nnormal block (#20) 0x00790630" The only other thing I see is, memory check error at 0x00790680 = 0x00, should be 0xFD. memory check error at 0x00790681 = 0x00, should be 0xFD. memory check error at 0x00790682 = 0x00, should be 0xFD. memory check error at 0x00790683 = 0x00, should be 0xFD. in my debug window. I compiled it on release. I get that 0xC000005 error after the program exits. Anyone know anything about this?
------------------------------------------------------------I wrote the best video game ever, then I woke up...


It sounds like you have allocated memory somewhere and it has overrun its bounds.

If you have any class instances declared, set breakpoints in their dtors to check and see where the memory gets deallocated .

Advertisement
You can also get these errors while using COM/ADO. If you fail to close your COM objects properly and ADO can''t clean up for you, you may get these errors.


Be sure to call the ->Close() methods on your objects. Also be sure to CoUnitialize the COM subsystem before exiting your program.

Aside from that the only additional help I could give you would be from looking at your code and telling you where you are playing with memory that you shouldn''t be.



Derek Licciardi
President
Elysian Productions Inc.
Derek Licciardi (Kressilac)Elysian Productions Inc.
Got it..

Here is the error:
  char byTemp[8];memset(byTemp, 0, sizeof(char[32]);  


Just to show you how stupid a mistake it was..
Fixed it.
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Glad you caught the error. Here''s a better way to do that code:
char byTemp[8];memset (byTemp, 0, sizeof (byTemp)); 


If you have a non-dynamic array, sizeof (s) will return the amount of memory taken by the entire array. Declaring your memset this way means that the memset line will always be right, no matter if you change the number of bytes in byTemp later, or even the type of byTemp. A handy trick, IMHO.

Also, I don''t know if you understand what the "Damage after normal block" error is, but I thought I''d explain it for anybody else watching who doesn''t know what this is.

Microsoft Visual C++, when you compile in debug mode, does a lot of nifty things when you allocate and release memory. When memory is allocated (even on the stack), the compile pads bytes before and after the allocated space with a special pattern, and fills the allocated memory with a different pattern. This is why you see "CD" or "FE" patterns in memory. When memory is released, it is again filled with a different pattern, and the special pad bytes before & after the block are checked to make sure they''re the same pattern. If they''re not, you get the "damage before/after normal block" error, meaning something changed that memory, and you should look to see where you''re overrunning your bounds.

This topic is closed to new replies.

Advertisement