Slow Week

posted in The Enigma Code
Published October 08, 2006
Advertisement
As the title says, this has been a bit of a slow week for me, so I don't have much to talk about. I did manage to embarrass myself at work this week. I coded a fairly simple function which didn't work correctly at first. Nothing new there. A lot of simple code fails to work perfectly first time. So I set a breakpoint and checked out what was happening in the function. The result I got was:
	if (current_value > persistent_value)	{->		// code	}
Where the -> indicates the current execution point. The debugger watch window showed the current values of current_value and persistent_value as (roughly):
current_value   : 4.1persistent_value: 3.8x10e38
So, you can understand my confusion. The debugger was telling me that current_value was considerably less than persistent_value, yet execution was still entering the body of the if. Much confusion, stepping through the assembly, even using the Intel reference manuals to manually disassembly the machine code followed. From everything I could tell the compiler was simply generating wrong code, reading from a different stack offset at different points. Clearly this was impossible. Modern compilers do not generate wrong code. At least not with such simple source code.

The answer turned out to be exceedingly simple and was discovered after a co-worker looked through the code with me. A simple copy-paste error had left me with:
float persistent_value = std::numeric_limits< float >::max();for (some_condition){	float current_value = get_current_value();	if (current_value > persistent_value)	{		// code		float persistent_value = std::numeric_limits< float >::max();	}	// code that modifies persistent_value}

The intent had been to reset persistent_value to the maximum float value, but by copying and pasting I'd actually declared a local variable instead of modifying the more broadly scoped persistent_value. The debugger couldn't distinguish between the two persistent_values, so as soon as execution entered the if block it reported the value of persistent_value in the if as that of the local variable, whereas the more broadly scoped persistent_value still has a value of about 3.1.

So, that was my moment of severe embarrassment this week. Feel free to make me feel better my documenting your own foul-ups in reply, or make me feel worse by claiming never to make such stupid mistakes.

On the mod front I'll still working through the JasPer source and likely will be for some time to come. I'm finally starting to get into the meat of the code now. I'm sure things would be much easier if I had a copy of the Jpeg2000 standard, but I don't. Since I'm not going to be able to show you a screenshot of what I'm working on for a while yet, and because my inane babblings must be quite tedious without any graphical interludes I got permission to post an existing screenshot from the mod here, showing the distance fog I quickly hacked into an existing Unreal Tournament renderer:



EDIT: In other news, phantom's treatise on trees should be required reading this week.

?nigma
Previous Entry Brevity is Not a Virtue
Next Entry Ready, Aim, Fire!
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement