Always initialize your memory

Add comment!

April 26th, 2009

I ran into an interesting bug when I was messing with an early version of David's shadows. I was a little surprised to see my full name projected onto the ground:

Unitialized memory screenshot
My name inscribed in the terrain

I often hear that you should always initialize your memory before using it, but I had never seen such a vivid example of what happens when you don't! Mac OS X draws the screen using OpenGL, so if you use uninitialized VRAM as a texture, you can accidentally load discarded images from earlier computer use.

Here are a few more screenshots:

Unitialized memory screenshot
Unitialized memory screenshot

So, try not to display raw allocated memory to the user. :) You never know what might be in there.