What causes desktop corruption?

I’ve got my program set to run at 1024*768 @ 32 bit. 9 out of 10 times it exits fine but now and then the desktop gets garbled.

using what to create your context/clean up

base code from nehe.gamedev.net

A couple of the tutorials from www.gametutorials.com crash now and then as well. Might be some pointer related stuff deep in the code.

I use getasynckeystate and getcursorpos in my code but the check for ESC is normal windows message queue.