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...
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.