🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Buggin Out!

posted in noaktree leaves
Published February 04, 2005
Advertisement
Spent most of my day tracking down an obscure bug in my material editor. It was appearing to crash at random. Cause: There was corrupt data at a memory address. Turned out that I was accessing a dynamic array with a -1 index every once in a while and this corrupted the pointer so that when I went to delete [] the array the app crashed. Glad that's over. Thanks to the good old OutputDebugString().

Added individual subset selection using the mouse and extended list box. The interface is turning out really nice. Next I'll need to clean up and reorganize my modules cuz things are starting to get a little out of control [smile].
Previous Entry An Old Game
Next Entry Reforming my Ego
0 likes 5 comments

Comments

Muhammad Haggag
You could've avoided the trouble in the first place with vector's at member that throws an exception on out-of-bounds access attempts [smile].

Also, scattering _CrtCheckMemory() calls throughout your code can quickly help you identify the source of heap corruption.

My 2 cents [smile]
February 04, 2005 06:57 PM
noaktree
Thanks Coder!

edit: So are you saying that we shouldn't use dynamic arrays? Or just that we should use some sort of container if we do?

edit2: Yes I now see using _ASSERTE with _CrtCheckMemory() will be very usefull for apps made with VC++! [smile]
February 04, 2005 08:25 PM
Muhammad Haggag
Quote: edit: So are you saying that we shouldn't use dynamic arrays? Or just that we should use some sort of container if we do?

Basically, in C++, you should almost always use std::vector instead of raw arrays. And always use std::vector::at() to access elements, because it does bounds-checking. If profiling shows std::vector::at() is a bottleneck somewhere (in some oft-used inner-loop), switch to std::vector::operator[](), which simply generates code equivalent to what would have been generated with direct access to the raw array (i.e. no performance hit).

Bjarne - The Man (TM) - says it all. Read everything the guy has to say [smile]

Quote: edit2: Yes I now see using _ASSERTE with _CrtCheckMemory() will be very usefull for apps made with VC++!

You can also make use of _CrtSetDbgFlag for memory-leak tracking - it makes it a breeze (plug "Detecting and Isolating Memory Leaks Using Microsoft Visual C++" into google and read the MSDN article that comes up [smile])
February 04, 2005 10:28 PM
evolutional
Or instead of _CrtCheckMemory, I use Paul Nettles' mmgr, probably does very much the same thing though. It certainly helped me find some very obscure bugs.
February 05, 2005 04:49 AM
noaktree
Thanks to both of you!
February 05, 2005 08:55 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement