Dont you love those bugs that wont go away?

Published December 13, 2007
Advertisement
Hey everyone,

Today I decided to go back to EvolutionEngine again, along with my CRPG in development. I managed to develop a new codec to support better terrain support and management. No more ugly *.raw.

I managed to get it working, which is exciting [smile]

I ran into an interesting problem earlier though, that I thought was funny, and sad at the same time.

...Dont you love those bugs that just wont go away?

I do. This one particular problem came out of nowhere. Literally. While writing (and trying to figure out how I should parse this file format), everything was going pretty good.

I wrote two more lines of code... ...then BAM! I get a runtime stack corruption around my variable called "file".

Hm... Okay, I thought. I'll just comment those two lines of code and see what happens...

...BAM, it hit again. The same error, and same "file" variable.

Hm...By now, I knew something was fishy. After all, the code worked fine before I put those two new lines in. Perhaps there is a problem with "file"?

So, to get around this error, and trying to narrow down what can cause this, I put the "file" variable in the global namespace. Great! Now the error cannot be caused by the variable in any way as it is not on the stack.

...BAM. Again! Except this time, a different variable was listed... "info".

Okay...It was now apparent that somewhere in that segment of code I am somehow corrupting the stack in some way. ...But how?

To test this theory, I commented almost every line in the routine to track where it might be happening. The debugger always broke back to this same routine whenever this happened, so I knew something was wrong with the routine. But, how can there be anything wrong if there is nothing in it?

So, I try again......

...BAM, Yet again!

Now I was worried. This bug has grown fangs, and turned into a huge monkey-like crazy red-eyed gleaming superfly. Whats worse? My code was already ontop his plate.

Oh oh, I thought. Looking through my code, I knew there was only a limited of time left. What to do, What to do!?

Then light opened up (Somehow--I dont know how), and I worked through my code and went over this...

	std::fstream file;        //etc...	file.read ( (char*)info.m_ltw.m_heightScale, 2 );	file.read ( (char*)info.m_ltw.m_baseHeight, 2 );

...At first, I did not see anything wrong with this code. After all, both m_heightScale and m_baseHeight are WORD-sized integers. Yes...Thats when the error stood out more then ever.

(There is a big error with the above code. I will leave it for our readers to see if they can find it[smile])

PS: I been working on this tonight a long time (About 7hrs). Jeeze...I should goto bed; (Thats right, I said the evil word)

Well...Thats my story for tonight.
Previous Entry Dating rule #1
0 likes 3 comments

Comments

Gaiiden
*thinks*

Yea I got nothing. Sad to see how far my C++ and general low-level programming knowledge has atrophied *sigh*
December 13, 2007 02:50 AM
dcosborn
Hehe, that was a good post, cause I've been there too and I can feel your pain.
Quote:Original post by Crypter
both m_heightScale and m_baseHeight are WORD-sized integers

Its cause you didn't take the address right? And the C-style casting allowed you to convert the integers to pointers (bad, bad).
December 13, 2007 04:57 AM
Crypter
Quote:
Its cause you didn't take the address right? And the C-style casting allowed you to convert the integers to pointers (bad, bad).

Yep--That was indeed the problem. (I didnt type the address-of (&) operator, but was thinking "address of", because it was an integral value. Ugh!!)

Just to think, one character off caused all of this.
December 13, 2007 11:20 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement